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);
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" />
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With