Dialog去除边框代码

本文介绍如何通过创建自定义样式文件来调整Android应用中对话框的显示效果,包括去除边框、背景透明等设置。


使用样式文件,在values 目录下新建styles.xml文件





  1. <resources>

  2. <style name="dialog" parent="@android:style/Theme.Dialog">

  3. <item name="android:windowFrame">@null</item>

  4. <itemname="android:windowIsFloating">true</item>

  5. <itemname="android:windowIsTranslucent">false</item>

  6. <itemname="android:windowNoTitle">true</item>

  7. <itemname="android:background">@android:color/black</item>

  8. <item name="android:windowBackground">@null</item>

  9. <itemname="android:backgroundDimEnabled">false</item>

  10. </style>

  11. </resources>



调用时,使用AlerDialog的接口类



  1. Dialog dialog =new Dialog(SetActivity.this,R.style.dialog);

  2. dialog.setContentView(R.layout.test);

  3. dialog.show();

  4.  

  5. public Dialog(Context context, int theme) {

  6. mContext =new ContextThemeWrapper(context, theme==0?com.android.internal.R.style.Theme_Dialog : theme);

  7.  

  8. mWindowManager =(WindowManager)context.getSystemService("window");

  9. Window w = PolicyManager.makeNewWindow(mContext);

  10. mWindow = w;

  11. w.setCallback(this);

  12. w.setWindowManager(mWindowManager, null, null);

  13. w.setGravity(Gravity.CENTER);

  14. mUiThread = Thread.currentThread();

  15. mDismissCancelHandler =new DismissCancelHandler(this);

  16. }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值