Android-触摸外部视图时如何关闭注入微调器的AlertDialog? [英] Android - How an AlertDialog injected with spinner can be closed when touched outer view?
本文介绍了Android-触摸外部视图时如何关闭注入微调器的AlertDialog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我要关闭的是Spinner对话框和在这些框之外单击时创建的自定义对话框。有人知道如何处理吗?
Basically what I want to do is closing Spinner's Dialog Box and the Customized Dialog I've created when clicked outside of those boxes. Anyone knows how to handle these?
dialog.xml,我的微调工具的xml,下面的MakeandShowDialogBoxBox函数:
dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/scheduleTable"
android:layout_height="wrap_content"
android:layout_width="match_parent"
></TableLayout>
</LinearLayout>
Spinner XML
<Spinner
android:id="@+id/spinList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/strDepartmentNames"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:spinnerMode="dialog"
android:paddingTop="15dp"
android:paddingBottom="15dp" />
makeAndShowDialogBox
private void makeAndShowDialogBox() {
AlertDialog.Builder myDialogBox = new AlertDialog.Builder(this);
final LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View dialogView = layoutInflater.inflate(R.layout.dialog, null);
// Set three option buttons
myDialogBox.setPositiveButton("Close",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
myDialogBox.setView(dialogView);
myDialogBox.create();
myDialogBox.show();
}
推荐答案
您只需在以下位置添加此选项您的对话框
you just add this option in your dialog
myDialogBox.setCancelable(true);
这篇关于Android-触摸外部视图时如何关闭注入微调器的AlertDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文