Reputation: 2923
I want it to be impossible for the soft keyboard to pop up due to an action in the my webView. That's because I have a custom "keyboard" consisting of buttons below the webView. However, I don't want to completely disable the keyboard for my application, as I have to use it in different contexts. It just shouldn't show up when the user clicks on an input field inside the webView. I also don't want the keyboard to show and instantaneously hide again.
I currently have this in my AndroidManifest.xml
:
android:windowSoftInputMode="stateAlwaysHidden"
I already tried disabling the focus of the webView, but then I can't enter text with my custom "keyboard" either, as the input field of the webView aren't focused.
I also tried this in onCreate
, but it didn't work (the keyboard still showed up):
View focusedView = this.getCurrentFocus();
if (focusedView == null)
return;
InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (manager == null)
return;
manager.hideSoftInputFromWindow(focusedView.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Upvotes: 11
Views: 2095
Reputation: 69681
Use this in your WebView
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
Try this
<WebView
android:id="@+id/myWebView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false" />
Upvotes: 5
Reputation: 17
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
call this before everything
Upvotes: 0
Reputation: 1366
Paste this in your onCreate
method after setContentView
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Keyboard wont show when you run this activity.
Upvotes: -1
Reputation: 540
sorry I'm late on this one.
But here is the solution:
Add this in your parent layout:
android:descendantFocusability="blocksDescendants"
Set these two properties of your WebView:
android:focusable="false"
android:focusableInTouchMode="true"
This works for me :)
Upvotes: 8