有两种方法:都是使用Style指定相关的属性
1.在style中显示的设置
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <style name="DialogStyle" parent="@android:style/Theme.Dialog">
- <item name="android:windowBackground"> @android:color/transparent </item>
- <item name="android:backgroundDimEnabled">false</item> </style>
- </resources>
在Activity中覆写onCreateDialog()方法
- @Override
- protected Dialog onCreateDialog(int id) {
- // TODO Auto-generated method stub
- if(id == 1){
- Dialog dialog = new Dialog(this, R.style.DialogStyle);
- dialog.setContentView(R.layout.start_dialog);
- dialog.show();
- isDialogShow = true;
- return dialog;
- }
- return super.onCreateDialog(id);
- }
2.在代码中使用语句设定
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <style name="DialogStyle" parent="@android:style/Theme.Dialog">
- <item name="android:windowBackground"> @android:color/transparent </item>
- </style>
- </resources>
java代码
- @Override
- protected Dialog onCreateDialog(int id) {
- // TODO Auto-generated method stub
- if(id == 1){
- Dialog dialog = new Dialog(this, R.style.DialogStyle);
- dialog.setContentView(R.layout.start_dialog);
- Window window = dialog.getWindow();
- WindowManager.LayoutParams params = window.getAttributes();
- params.dimAmount = 0f;
- window.setAttributes(params);
- dialog.show();
- isDialogShow = true;
- return dialog;
- }
- return super.onCreateDialog(id);
- }
两种方法其实一样,最后效果就是弹出对话框时背景不会变暗了。