【发布时间】:2021-06-04 19:15:37
【问题描述】:
**Please help me out where I have done wrong**
单击我的外部区域时,我无法关闭对话框 仅当我按下移动键中的 backpress 时屏幕才会消失。
Dialog dialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.dialog_child_product_two);
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount = 0.7f; // Dim level. 0.0 - no dim, 1.0 - completely opaque
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(true);
*// Views inflated in my dialog to perform some actions on keypress*
Button btnDone = (Button) dialog.findViewById(R.id.txt_done);
btnDone.setOnClickListener(view -> {
// Do some work here after some action performed
dialog.dismiss();
});
dialog.show();
【问题讨论】:
-
如果您希望在您在对话框外触摸时取消调用
setCancelable(false),是否有原因?
标签: android android-layout dialog android-styles android-windowmanager