问题
I have DialogFragment and a WebView into it, that opens with Google Forms web page. But keyboard not showing when clicking on text input field. Any suggestions? Original Android 8.1 (Nexus 5x).
WebView webView = binding.webView;
webView.requestFocus(View.FOCUS_DOWN);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(google_form_url);
Layout:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data />
<WebView
android:id="@+id/webView"
style="?android:attr/webViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true" />
</layout>
Manifest:
<activity
android:name="com.keeple.april.Activity2"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize"/>
回答1:
Did you try to add touch listener below requestFocus?
webView.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus())
{
v.requestFocus();
}
break;
}
return false;
}
});
来源:https://stackoverflow.com/questions/55906042/android-webview-doesnt-show-keyboard-when-text-edit-field-got-a-focus