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

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

1.在style中显示的设置

<?xml version="1.0" encoding="utf-8"?>        


在Activity中覆写onCreateDialog()方法

@Overrideprotected Dialog onCreateDialog(int id) {// TODO Auto-generated method stubif(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"?>        

 

java代码

@Overrideprotected Dialog onCreateDialog(int id) {// TODO Auto-generated method stubif(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);}

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