在 Java Android Studio 中删除对话框周围的触摸
Delete touch around a dialog in Java Android Studio
我正在研究如何消除对话框周围的触摸效果
我在未检测到连接时创建了一个对话框
代码
@Override
public void onErrorResponse(String _param1, String _param2) {
final String _tag = _param1;
final String _message = _param2;
nc.setTitle("No connection");
nc.setIcon(R.drawable.ic_launcher);
nc.setMessage("Turn on your connection and then relaunch the app");
nc.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
i.setClass(getApplicationContext(), SplashActivity.class);
startActivity(i);
}
});
nc.setNegativeButton("Close App", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
finish();
}
});
nc.create().show();
}
};
}
出现对话框时,它必须设为 350x100
当我单击对话框周围的屏幕时,它会删除
我想知道是否可以在显示对话框时取消触摸周围的触摸?
您可能需要在创建过程中添加 setCancelable(false)
https://developer.android.com/reference/android/app/AlertDialog
试试这个:dialog.setCanceledOnTouchOutside(false);
。它仍然允许您使用后退按钮取消对话框,但它会阻止对话框在触摸它时关闭。
编辑
在您的代码中,您应该将末尾的 nc.create().show();
更改为:
AlertDialog alertDialog = nc.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
我正在研究如何消除对话框周围的触摸效果
我在未检测到连接时创建了一个对话框
代码
@Override
public void onErrorResponse(String _param1, String _param2) {
final String _tag = _param1;
final String _message = _param2;
nc.setTitle("No connection");
nc.setIcon(R.drawable.ic_launcher);
nc.setMessage("Turn on your connection and then relaunch the app");
nc.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
i.setClass(getApplicationContext(), SplashActivity.class);
startActivity(i);
}
});
nc.setNegativeButton("Close App", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
finish();
}
});
nc.create().show();
}
};
}
出现对话框时,它必须设为 350x100
当我单击对话框周围的屏幕时,它会删除
我想知道是否可以在显示对话框时取消触摸周围的触摸?
您可能需要在创建过程中添加 setCancelable(false)
https://developer.android.com/reference/android/app/AlertDialog
试试这个:dialog.setCanceledOnTouchOutside(false);
。它仍然允许您使用后退按钮取消对话框,但它会阻止对话框在触摸它时关闭。
编辑
在您的代码中,您应该将末尾的 nc.create().show();
更改为:
AlertDialog alertDialog = nc.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();