我有一个正在使用主题的活动。对话框样式,使其成为另一个活动上方的浮动窗口。但是,当我在对话框窗口外(在后台活动上)单击时,对话框关闭。我怎样才能阻止这种行为?
当前回答
Dialog dialog = new Dialog(context)
dialog.setCanceledOnTouchOutside(true);
//use this to dismiss the dialog on outside click of dialog
dialog.setCanceledOnTouchOutside(false);
//use this for not to dismiss the dialog on outside click of dialog.
观看这个链接了解更多关于对话的细节。
dialog.setCancelable(false);
//used to prevent the dismiss of dialog on backpress of that activity
dialog.setCancelable(true);
//used to dismiss the dialog on onbackpressed of that activity
其他回答
简单地说,
alertDialog.setCancelable(false);
防止用户在对话框外单击。
Dialog dialog = new Dialog(context)
dialog.setCanceledOnTouchOutside(true);
//use this to dismiss the dialog on outside click of dialog
dialog.setCanceledOnTouchOutside(false);
//use this for not to dismiss the dialog on outside click of dialog.
观看这个链接了解更多关于对话的细节。
dialog.setCancelable(false);
//used to prevent the dismiss of dialog on backpress of that activity
dialog.setCancelable(true);
//used to dismiss the dialog on onbackpressed of that activity
在jetpack组合中,使用遣散onclickoutside = false属性来防止关闭。
AlertDialog(
title = {
Text("Title")
},
text = {
Text(text = name)
},
onDismissRequest = onDismiss,
confirmButton = {
TextButton(onClick = onDismiss ) {
Text("Yes")
}
},
dismissButton = {
TextButton(onClick = onDismiss ) {
Text("Cancel")
}
},
properties = DialogProperties(
dismissOnClickOutside = false
)
)
}
我在onCreate()中使用这个,似乎可以在任何版本的Android上工作;在5.0和4.4上测试。x,不能在姜饼上测试,三星设备(Note 1运行GB)默认是这样的:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
setFinishOnTouchOutside(false);
}
else
{
getWindow().clearFlags(LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
}
super.onCreate(savedInstanceState);
builder.setCancelable(假);
Mensaje(视图v){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("¿Quieres ir a el Menú principal?");
builder.setMessage("Al presionar SI iras a el menú y saldras de la materia.");
builder.setPositiveButton("SI", null);
builder.setNegativeButton("NO", null);
builder.setCancelable(false);
builder.show();
}
推荐文章
- Java Regex捕获组
- Openssl不被视为内部或外部命令
- 如何添加自定义方法到Spring Data JPA
- 如何在Ubuntu中设置Java环境路径
- 无法执行dex:在Eclipse中超过GC开销限制
- 有人能解释一下JPA和Hibernate中的mappedBy吗?
- 是什么导致JNI调用变慢?
- Java中的&和&&有什么区别?
- 使用Java的Collections.singletonList()?
- 如何以编程方式将视图添加到视图
- 单击url会打开默认浏览器
- Maven使用多个src目录编译
- 导入时无法解析符号
- 使用Retrofit刷新OAuth令牌,而不修改所有调用
- 多个dex文件定义了landoid /support/v4/accessibilityservice/AccessibilityServiceInfoCompat