0

Is it possible to hide soft keyboard when activity?.currentFocus and other similar methods return null?

vrgrg
  • 368
  • 1
  • 12
  • 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
  • 1
    Ok, I couldn't find the root cause and solved it by setting softInputMode to always hidden – vrgrg Jan 28 '21 at 13:03

1 Answers1

2

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
  • 171
  • 9