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.
Asked
Active
Viewed 998 times
-2
-
show your code. – ak sacha Mar 17 '17 at 05:02
-
Possible Duplicate http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard – Bhavik Mehta Mar 17 '17 at 06:52
-
1Possible duplicate of [Close/hide the Android Soft Keyboard](http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard) – Marek Urbanowicz Mar 17 '17 at 10:57
2 Answers
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);
}
}
}

Harris Solangi
- 56
- 4
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
- 12,540
- 3
- 28
- 48