我在创建时创建了这个透明窗口,如何才能创建它,而不必按下后退按钮,在按下屏幕上的任何位置时隐藏视图?
代码:
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.help);
dialog.setCanceledOnTouchOutside(true);
final Window window = dialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
RelativeLayout rl = (RelativeLayout) dialog.findViewById(R.id.relativeLayout);
rl.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
答案 0 :(得分:0)
使用
dialog.setCancellable(true);
@Val您可以在对话框的视图中添加单击侦听器并将其关闭