android - 如何阻止警报对话框自动消失

标签 android android-dialog

下面是我的代码,用于在 GPS 关闭时提醒用户。在这里,我的用户必须单击其中一个选项并进一步移动。但是如果用户点击屏幕上除此警报以外的其他地方,此警报就会消失。如何阻止此警报对话框自动消失。请帮忙

Builder bd = new AlertDialog.Builder(myTest.this);
    bd.setTitle("Alert");       
    bd.setMessage("GPS is disabled. Do you want to");
    bd.setNegativeButton("Enable GPS", new DialogInterface.OnClickListener() {              
                public void onClick(DialogInterface dialog, int which) {
                    startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }});            
            bd.setPositiveButton("Close App", new DialogInterface.OnClickListener() {               
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
                });
    bd.show();  

最佳答案

使用 bd.setCancelable(false)。这将使它只能通过按下按钮才能消失。

关于android - 如何阻止警报对话框自动消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14386561/

相关文章:

javascript - 如何使用Cordova管理Android手机的文件系统

android - 在 DialogFragment 的标题中放置一个按钮

Android 对话框导致 android.view.WindowManager$BadTokenException : Unable to add window

android - 如何从android中的USB驱动器读取文件?

android - Android 众筹应用的 PayPal 集成

android - Android 4.1.2、三星 galaxy s3、HTC 上的 Phonegap 相机崩溃

android - onClick 事件不适用于 android 中的嵌套 ListView 项控件

c# - 将 Camera OnActivityResult 传递给 Webservice 以作为图像保存在服务器上

android - 如何在方向更改时保留日期时间对话框的状态?

android - AlertDialog 弹出两次