Android's webview keyboard does not disappear

Asked 2 years ago, Updated 2 years ago, 78 views

http://dotinstall.com/lessons/browser_android_v2/32604
I wrote the code as per the above site, but when I see it in the emulator, the keyboard appears by default, and it doesn't disappear even if I unfocus the edit text.
How do I hide my keyboard?

android java android-studio webview

2022-09-30 11:44

1 Answers

To hide the soft keyboard, you must write the code you want to hide when the user hides the or app is out of focus (for example).

For example, a listener who hides the keyboard when the focus is off will write:

View.OnFocusChangeListener focusLostSoftKeyboardHide=newView.OnFocusChangeListener(){
    @ Override
    public void onFocusChange (View view, boolean hasFocus) {
        if(!hasFocus){
            InputMethodManager imm=(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
};


2022-09-30 11:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.