Android Webview doesn't show keyboard when text edit field got a focus

萝らか妹 提交于 2019-12-11 18:33:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!