【Android】AlertDialog禁止返回键

2025-05-21 22:11:28

1、一般的实现弹出框的代码AlertDialog.Builder localBuilder = new AlertDialog.Builder(activity);localBuilder.setMessage(msg);localBuilder.setTitle("提示");localBuilder.setPositiveButton("确认",new DialogInterface.OnClickListener() { public void onClick( DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { paramAnonymousDialogInterface.dismiss(); }});localBuilder.setNegativeButton("取消",new DialogInterface.OnClickListener() { public void onClick( DialogInterface paramAnonymousDialogInterface,int paramAnonymousInt) { paramAnonymousDialogInterface.dismiss(); }});localBuilder.setCancelable(false);localBuilder.create().show();

【Android】AlertDialog禁止返回键

3、//由于设置alertDialog.setCancelable(false);但是按了KeyEvent.KE鳔柩寞泷YCODE_SEARCH,对话框还是会Dismiss掉。设置setOnKeyListener屏蔽KeyEvent.KEYCODE_SEARCH的触法处理。

【Android】AlertDialog禁止返回键

5、alertDialog.setCancelable(false);然后设置setOnKeyListener()(自己重写按钮触法监听)

【Android】AlertDialog禁止返回键
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢