/** * 自定义的对话框Custom_Dialog */ private void showDialog() { // 获取自定义布局 LayoutInflater inflater = LayoutInflater.from(MainActivity.this); View view = inflater.inflate(R.layout.customDialog, null); //View view = View.inflate(this, R.layout.custom_Dialog, null); // 创建对话框,使用自定义样式 Dialog dialog = new Dialog(this,R.style.customDialog); // 点击事件监听处理 et_pwd = (EditText) view.findViewById(R.id.et_normal_entry_pwd); Button bt_normal_ok = (Button) view.findViewById(R.id.bt_normal_dialog_ok); Button bt_normal_cancle = (Button) view.findViewById(R.id.bt_normal_dialog_cancle); bt_normal_ok.setOnClickListener(this); bt_normal_cancle.setOnClickListener(this); // 添加布局到对话框 dialog.setContentView(view); // 设置对话框显示属性 Window dialogWindow = dialog.getWindow(); WindowManager.LayoutParams params = dialogWindow.getAttributes(); dialogWindow.setGravity(Gravity.BOTTOM); // 对话框显示方位 dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); // 背景变暗 params.x = 0; // 基于显示方位的水平偏移量 params.y = 0; // 基于显示方位的垂直偏移量 params.width = LayoutParams.FILL_PARENT; // 水平填充效果 params.height = LayoutParams.WRAP_CONTENT; // 垂直填充效果 params.dimAmount = 0.7f; // 背景黑暗度 dialogWindow.setAttributes(params); dialog.show(); // 显示对话框 }