Reputation: 127
I've implemented an app with a NavigationDrawer and some Fragments. But everytime I change Fragment with the NavigationDrawer, the soft keyboard keeps popping up, even if there's no EditText on the screen.
How can I solve this?
Upvotes: 0
Views: 189
Reputation: 1
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
This helped me out. I hope it works.
Upvotes: 0
Reputation: 4969
Add this line of code in your activity
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
And try with adding to fragment also.
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Upvotes: 1
Reputation: 11467
Try This in your BaseActivity or Main Activity
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
Upvotes: 0
Reputation: 5619
Have you tried adding this to your manifest for the activity:
android:windowSoftInputMode="stateHidden"
Upvotes: 1