2014-11-24 50 views
0

如何在对话框外单击对话框微调器?

我尝试它的Nexus 7(2013年),我可以在对话框微调之外单击以清除它,而不在片段添加任何代码,而不是在三星平板工作,所以我想知道如何将其关闭或东西我错过添加。如何在对话框外单击忽略微调器?

我发现了一些关于这个Android - How an AlertDialog injected with spinner can be closed when touched outer view?的链接。 但是Object - Spinner没有setCancelable(true)方法。

<Spinner 
     android:id="@+id/dialog_spinner" 
     android:layout_width="100dip" 
     android:layout_height="38ip" 
     android:spinnerMode="dialog" 
     /> 

谢谢。

回答

0
@Override 
public void onFocusChange(View v, boolean hasFocus) { 

if (!hasFocus) v.setVisibility(View.GONE); 

} 
0

如果你没有setCancelable方法也不setCanceledOnTouchOutside使用此功能:

public static void clickOutSideSpinner(View view) 
     { 
      // Configure touch listener for all views except edittext,Button and Spinner 
      if (!(view instanceof EditText) 
       &&!(view instanceof Button) 
       &&!(view instanceof Spinner)) 
      { 
       view.setOnTouchListener(new OnTouchListener() 
       { 
        @Override 
        public boolean onTouch(View v, MotionEvent event) 
        { 
         //here you close your dialog spinner 

         return false; 
        } 
       }); 
      } 

      //runs through all the children views . 
      if (view instanceof ViewGroup) 
      { 
       for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) 
       { 
        View innerView = ((ViewGroup) view).getChildAt(i); 
        closeSlidingDrawerOnTouch(innerView); 
       } 
      } 
     } 

在的onCreate调用你的函数,并通过布局:

@Override 
     protected void onCreate(Bundle savedInstanceState) 
     { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 

      TextView textviw1 = (TextView) findViewById(R.id.textviw1); 
      Spinner spinner1 = (Spinner) findViewById(R.id.spinner1); 
      Button button1 = (Button) findViewById(R.id.button1); 

      //change to other layout if you use other 
      LinearLayout layout1 = (LinearLayout) findViewById(R.id.layout1); 

      clickOutSideSpinner(layout1); 

     } 
0

AlertDialog.Builder有setCancelable(布尔取消)方法,您需要传递true来关闭对话框,然后单击对话框外部的对话框。

确保您的包含微调对话框已取消属性设置为真

参考http://developer.android.com/reference/android/app/AlertDialog.Builder.html 此属性的描述。

+1

这是微调。在Spinner对象中,没有setCancelable(boolean cancelable)方法。 http://developer.android.com/reference/android/widget/Spinner.html – Andy 2014-11-25 03:50:44

相关问题