-2

I want to hide soft keyboard when click on hamburger Icon in FragmentDrawer.I am using ActionBarDrawerToggle in Fragment. When I use Input Method Manager in onDrawerOpened and onDrawerClosed , it show error getSystemService and getCurrentFocus method cannot resolve.

lavi
  • 65
  • 7

2 Answers2

1

Set the "Id" of the Main Layout. and in the "OnClickListener" call the method pasted below.

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

Use Activity to 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); 
        }
sasikumar
  • 10,919
  • 2
  • 21
  • 42