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

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

1.在style中显示的设置



        


在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.在代码中使用语句设定



        

 

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);
		
	}

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


你可能感兴趣的:(android)