Android中使Dialog显示时背景不变暗

有两种方法:都是使用Style指定相关的属性

1.在style中显示的设置

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <style name="DialogStyle" parent="@android:style/Theme.Dialog">  
  4.         <item name="android:windowBackground"> @android:color/transparent </item>  
  5.         <item name="android:backgroundDimEnabled">false</item>    </style>      
  6. </resources>  


在Activity中覆写onCreateDialog()方法

[java]  view plain copy
  1. @Override  
  2.     protected Dialog onCreateDialog(int id) {  
  3.         // TODO Auto-generated method stub  
  4.         if(id == 1){  
  5.               
  6.             Dialog dialog = new Dialog(this, R.style.DialogStyle);  
  7.             dialog.setContentView(R.layout.start_dialog);  
  8.                   
  9.             dialog.show();  
  10.             isDialogShow = true;  
  11.             return dialog;  
  12.         }         
  13.           
  14.         return super.onCreateDialog(id);  
  15.           
  16.     }  


2.在代码中使用语句设定

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <style name="DialogStyle" parent="@android:style/Theme.Dialog">  
  4.         <item name="android:windowBackground"> @android:color/transparent </item>  
  5.           
  6.     </style>      
  7. </resources>  

 

java代码

[java]  view plain copy
  1. @Override  
  2.     protected Dialog onCreateDialog(int id) {  
  3.         // TODO Auto-generated method stub  
  4.         if(id == 1){  
  5.               
  6.             Dialog dialog = new Dialog(this, R.style.DialogStyle);  
  7.             dialog.setContentView(R.layout.start_dialog);  
  8.               
  9.             Window window = dialog.getWindow();  
  10.             WindowManager.LayoutParams params = window.getAttributes();  
  11.             params.dimAmount = 0f;  
  12.             window.setAttributes(params);     
  13.             dialog.show();  
  14.             isDialogShow = true;  
  15.             return dialog;  
  16.         }         
  17.           
  18.         return super.onCreateDialog(id);  
  19.           
  20.     }  

两种方法其实一样,最后效果就是弹出对话框时背景不会变暗了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值