I have a strange case, I use a webview to open a form page, which allow user to input some information in it. When I try it in some device such as Samsung, it works okay, but when I tried it in other device such as xiaomi, asus, etc it doesn't work. the keyboard popup, but when I typed it, the text box in the page just lost focus. I've found a work around using this code, but there is a down side, the webview on the samsung always go back to top each time i touch the screen (but on xiaomi, etc works okay). Is there any way to make it 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 the 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 the answer from this question but none of them works properly Why is Android WebView refusing user input?