我已经尝试学习和使用 Android Studio 大约 3 周了。我刚刚遇到了一种情况,即 AlertDialogue 在点击肯定按钮时不会关闭。
private void showGPSDisabledAlertToUser() {
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(this);
}
builder.setTitle("Turn On Location / GPS");
builder.setCancelable(false);
builder.setMessage("Application Needs To Determine Device's Physical Location.");
builder.setPositiveButton("YES, TURN ON", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); // This ain't working
goToInternetSettings();
}
});
builder.setNegativeButton("NO, CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
closeApplication();
} …Run Code Online (Sandbox Code Playgroud)