0

I'm using a webView (full screen) which has its own keyboard when needed. I want to disable the android keyboard popping up every time.

I've tried doing that with hideSoftInputFromInputMethod(getCurrentFocus().getWindowToken(), 0); but it doesnt work. Nor does android:windowSoftInputMode="stateAlwaysHidden"
or getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

BVtp
  • 2,308
  • 2
  • 29
  • 68
  • Possible duplicate of [Android: Backspace in WebView/BaseInputConnection](http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection) – marcinj Dec 29 '15 at 11:25

5 Answers5

0

You have to add android:windowSoftInputMode="stateAlwaysHidden" for each activity in manifest file. like this example

    <activity
        android:name=".MainActivity"
        android:windowSoftInputMode="stateAlwaysHidden" />
Umer
  • 1,566
  • 2
  • 20
  • 31
  • As I mentioned in my post - I've tried that. Unfortunately it doesn't help for some reason – BVtp Dec 29 '15 at 11:20
0

Use below function and call it in onTouch() of webview:

public static void hideSoftKeyboard(Activity activity) {
    try {
        InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }

}
user5716019
  • 598
  • 4
  • 17
0

Add following code in main(parent) layout in your layout.xml

android:descendantFocusability="blocksDescendants"

Hope it will work. And set following property in your webview

android:focusable="false" 
android:focusableInTouchMode="true"



See it:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:descendantFocusability="blocksDescendants"
    android:paddingBottom="@dimen/activity_vertical_margin"     tools:context=".MainActivityFragment">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="false"
        android:focusableInTouchMode="false">
    </WebView>
</RelativeLayout>
Kuldeep Kulkarni
  • 796
  • 5
  • 20
0
 if (mActivity.getCurrentFocus() != null) {
            InputMethodManager inputMethodManager = (InputMethodManager) mActivity.getSystemService(mActivity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(), 0);
        }
0

Try this:

<activity          
            android:configChanges="keyboard|keyboardHidden"
            android:windowSoftInputMode="stateAlwaysHidden">