Is it possible to hide soft keyboard when activity?.currentFocus
and other similar methods return null
?
Asked
Active
Viewed 218 times
0

vrgrg
- 566
- 4
- 17
-
Here is a great answer to your question: https://stackoverflow.com/a/17789187/14759470 – SlothCoding Jan 28 '21 at 11:03
-
Maybe my question is not complete. I used all possible solutions from So but none worked. The keyboard shows anyway after the bottom sheet dialog is closed. The dialog closes the keyboard `onDismiss`, but it pops up again once the dialog is closed. So I'm wondering what forces it to open? – vrgrg Jan 28 '21 at 11:30
-
1Ok, I couldn't find the root cause and solved it by setting softInputMode to always hidden – vrgrg Jan 28 '21 at 13:03
1 Answers
0
yes you can use focuschangelistners for your edittext fields like this:
txtName.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus) {
hideKeyboard();
}
}
});

shafaq ahsan
- 201
- 3
- 10
-
Yes, but I get null when trying to get focused view and the keyboard is still shown – vrgrg Jan 28 '21 at 11:37
-
Actually on global view tree observer no focus change takes place. The global focus change listener is not triggered – vrgrg Jan 28 '21 at 12:38