2016-12-08 5 views
4

DialogFragmentの末尾にAppCompatAutoCompleteTextViewがあります。キーボード非表示オートコンプリートテキストビュードロップダウン

ランドスケープモードのタブレット(API 19)では、候補リストに要素が1つしかない場合、ドロップダウンはキーボードでカバーされます。より多くの要素がある場合、ドロップダウンは上向きになり、うまく動作します。

モバイル(API 22)では、候補リストに要素が1つしかない場合でも、ドロップダウンは常に上に表示されます。

私はすでにandroid:windowSoftInputMode="adjustPan|stateHidden"をマニフェストのアクティビティに追加しました。

ドロップダウンを常に上向きにするか、キーボードで覆わないようにするにはどうすればよいですか?

答えて

0
Work around the below the completionThreshold. Hope it works for you! 
<AutoCompleteTextView 
    android:id="@+id/someID" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:completionThreshold="1" /> 

または

autocomplete.setThreshold(2); 
0
public static void hideSoftKeyboard(Activity activity) { 
    InputMethodManager inputMethodManager = 
      (InputMethodManager) activity.getSystemService(
        Activity.INPUT_METHOD_SERVICE); 
    inputMethodManager.hideSoftInputFromWindow(
      activity.getCurrentFocus().getWindowToken(), 0); 
} 

public void setupUI(View view) { 

    // Set up touch listener for non-text box views to hide keyboard. 
    if (!(view instanceof EditText)) { 
     view.setOnTouchListener(new View.OnTouchListener() { 
      public boolean onTouch(View v, MotionEvent event) { 
       hideSoftKeyboard(getActivity()); 
       return false; 
      } 
     }); 
    } 

    //If a layout container, iterate over children and seed recursion. 
    if (view instanceof ViewGroup) { 
     for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { 
      View innerView = ((ViewGroup) view).getChildAt(i); 
      setupUI(innerView); 
     } 
    } 
} 

あなたoncreatesetupUI(rootView.findViewById(R.id.parent));

にこの行を追加します。
関連する問題