How to hide keyboard when user clicks on text box in android webview

Can we hide the Android system keyboard when the user focuses or clicks on the html input elements inside the web view.

I tried hiding the keyboard on a webview user touch:

webView.setOnTouchListener(new View.OnTouchListener()
{
    @Override
    public boolean onTouch (View v, MotionEvent event){
        Toast.makeText(cx,"Web View Touch",Toast.LENGTH_LONG).show();
        v.onTouchEvent(event);
        InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

        }
            return true;
    }
})

But that does not work.

Is it possible to completely hide the keyboard for the application?

+4
source share
2 answers

You can control softkeyboard - handling the visibility of the input method for each action with a manifest as follows:

<activity
    android:name=".Main"
    android:windowSoftInputMode="stateAlwaysHidden" >

<activity
    android:name=".Main"
    android:windowSoftInputMode="stateHidden" >

, "next" edittext , "done" IME.

android:imeOptions="actionNext"
android:imeOptions="actionDone"

, - , - , :

android:descendantFocusability="blocksDescendants"

-:

android:focusable="false" 
android:focusableInTouchMode="false"
+2

manifest.xml..

android:windowSoftInputMode="stateHidden"

.

0

Source: https://habr.com/ru/post/1622353/


All Articles