5

Can we hide android system keyboard when user focuses or clicks on html input elements inside the webview.

I have tried hiding keyboard on user touches webview:

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 doesn't work.

Is there option to hide keyboard entirely for a app?

Sirisha
  • 123
  • 1
  • 6

2 Answers2

4

You can control the softkeyboard - Handling Input Method Visibility for each activity with the manifest like so:

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

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

You can also control it so it flows using 'next' from one edittext to the next and then hides again with 'done' using IME options.

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

I also realise the problem would be with using a webview and needing to also disable any keyboard from parent layouts,as the webview is separate from the activities in the manifest, so add this to any parent layout:

android:descendantFocusability="blocksDescendants"

and in the webview:

android:focusable="false" 
android:focusableInTouchMode="false"
Sirisha
  • 123
  • 1
  • 6
  • Hey it is working in emulator Nexus4 API 19. But while I am checking with Moto G through USB it is not working. Any idea regarding this issue. – Sirisha Dec 31 '15 at 16:02
1

try this in the activity in manifest.xml..

android:windowSoftInputMode="stateHidden"

it may help.

riaz hasan
  • 1,098
  • 1
  • 8
  • 20