Reputation: 605
when i navigate to another activity and get back to old activity keyboard shows. Not only this also whenever i show a alert dialog keyboard also shows after dialog dismiss.
in manifiest i use this configuartion : "adjustPan"
ı use this because my activity has a bottom navigation bar and if i dont use it bottom bar move above to keyboard and i dont want that.
I also tried "INPUT_STATE_ALWAYS_HIDDEN" but when i use this adjustpan method is not working and bottom bar moves above keyboard.
How can i prevent keyboard to show randomly?
Upvotes: 3
Views: 240
Reputation: 605
I solved this with this way.
I added this line to parent layout of every fragment that i don't want keyboard to show.
android:windowSoftInputMode="stateAlwaysHidden"
hope this helps somebody
Upvotes: 1
Reputation: 92
If keyboard shows when you get back to your activity, you can call hide keyboard method in your onResume():
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
Upvotes: 2