Android 设置Dialog点击返回键及屏幕不消失

2019-08-14 10:12:21 浏览数 (1)

只需在dialog的show方法前调用 setCanceledOnTouchOutside setCancelable 这两个方法即可 并设置参数为false 代码如下:

代码语言:javascript复制
Builder builder = new Builder(mContext);
        builder.setTitle("软件版本更新");
        builder.setMessage(updateMsg);
        builder.setNegativeButton("下载", new OnClickListener() {
            
            @Override
            public void onClick(DialogInterface dialog, int arg1) {
                // TODO Auto-generated method stub
                 dialog.dismiss();  
            }
        });

        noticeDialog = builder.create();
                //设置点击屏幕不消失
                noticeDialog.setCanceledOnTouchOutside(false);
                //设置点击返回键不消失
                noticeDialog.setCancelable(false);

        noticeDialog.show();

0 人点赞