AlertDialog和微调"对话框和QUOT;关闭当外界感动,怎么样? [英] AlertDialog and Spinner "Dialog" Close when touched outside, how?

查看:152
本文介绍了AlertDialog和微调"对话框和QUOT;关闭当外界感动,怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想要做的是关闭微调的对话框和自定义对话框我已经当这些箱子之外点击创建。任何人都知道如何处理这些?

dialog.xml,我微调的XML,下面MakeandShowDialogBox功能:

dialog.xml

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>    < TableLayout
        机器人:ID =@ + ID / scheduleTable
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =match_parent
        >< / TableLayout>< / LinearLayout中>

微调XML

 <微调
    机器人:ID =@ + ID / spinList
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:项=@阵列/ strDepartmentNames
    机器人:paddingLeft =5DP
    机器人:paddingRight =5DP
    机器人:spinnerMode =对话
    机器人:paddingTop =15dp
    机器人:paddingBottom会=15dp/>

makeAndShowDialogBox

 私人无效makeAndShowDialogBox(){    AlertDialog.Builder myDialogBox =新AlertDialog.Builder(本);    最后LayoutInflater layoutInflater =(LayoutInflater)getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);    最后查看dialogView = layoutInflater.inflate(R.layout.dialog,NULL);    //设置三个选项按钮
    myDialogBox.setPositiveButton(关闭
            新DialogInterface.OnClickListener(){
                公共无效的onClick(DialogInterface对话,诠释whichButton){                }
            });    myDialogBox.setView(dialogView);
    myDialogBox.create();
    myDialogBox.show();
}


解决方案

你只是你的对话框中添加此选项

myDialogBox.setCancelable(真);

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, My Spinner's xml, MakeandShowDialogBox function below :

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);

这篇关于AlertDialog和微调&QUOT;对话框和QUOT;关闭当外界感动,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆