2017-03-17 6 views
-2

フラグメントのドラッグバーでハンバーガーアイコンをクリックするとソフトキーボードを隠したい。フラグメント内のActionBarDrawerToggleを使用しています。 onDrawerOpenedとonDrawerClosedでInput Method Managerを使用すると、getSystemServiceエラーが表示され、getCurrentFocusメソッドで解決できません。 getCurrentFocusフラグメント内のナビゲーションドロワーをクリックするとアンドロイドソフトキーボードが表示されない

 @Override 
     public void onDrawerStateChanged(int newState) {    
     InputMethodManager inputManager = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 
     inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 
     InputMethodManager.HIDE_NOT_ALWAYS); 
     } 
+0

コードを表示します。 –

+0

重複している可能性がありますhttp://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard –

+1

[Androidソフトキーボードを閉じる/隠す]の可能な複製(http://stackoverflow.com/questions/ 1109022/close-hide-the-android-soft-keyboard) –

答えて

1

0

使用アクティビティは、メインレイアウトの "ID" に設定します。 "OnClickListener"では、以下にペーストされたメソッドを呼び出します。

public static void hideKeyboard(Activity activity) { 
     if (activity != null) { 
      if (activity.getCurrentFocus() != null) { 
       InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity 
         .INPUT_METHOD_SERVICE); 
       inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus() 
         .getWindowToken(), 0); 
      } 
     } 
    } 
関連する問題