Android WebView cannot receive keyboard input for any device
I have a weird case, I am using a webview to open a form page that allows the user to enter some information into it. When I try to use it on some devices like Samsung, it works fine, but when I try it on another device like xiaomi, asus, etc. it doesn't work. keyboard popup, but when I typed it, the textbox on the page just lost focus. I found it working using this code, but there is a downside, webview on samsung always goes back to the start every time I touch the screen (but on xiaomi etc. it works fine). Is there a way to make them work for both of them?
mPaymentWebView.getSettings().setJavaScriptEnabled(true);
mPaymentWebView.getSettings().setUseWideViewPort(true);
mPaymentWebView.requestFocus(View.FOCUS_DOWN);
mPaymentWebView.requestFocusFromTouch();
mPaymentWebView.requestDisallowInterceptTouchEvent(true);
mPaymentWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
Log.d("test keyboard","in");
mPaymentWebView.requestFocusFromTouch(); //this makes it work
return false;
}
});
and this is XML
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/web_view_payment"
android:focusableInTouchMode="true"
android:windowSoftInputMode="adjustResize"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progress_bar_webview"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:progress="5"
android:max="100"
android:progressDrawable="@drawable/progress_bar" />
</FrameLayout>
I've used all of the answer from this question, but none of them work as expected Why is Android WebView refusing user input?
+3
source to share