WebView textarea doesn't pop up the keyboard

前端 未结 11 1893
野趣味
野趣味 2020-11-28 06:06

When I display a WebView, I don\'t see the soft keyboard popping up. The hard keyboard also doesn\'t work!

What are the usual shortcomings.

The

相关标签:
11条回答
  • 2020-11-28 06:50

    try this --> the firstname is the name of the field and make sure it dose not have autofocus attribute.

        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                mWebView.loadUrl("javascript:document.getElementById(\"firstname\").focus();");
            }
        });
    
    0 讨论(0)
  • 2020-11-28 06:53

    one line answer and it is working nicely

    // define webview for browser
    wb = (WebView) findViewById(R.id.webView1);
    wb.requestFocusFromTouch();
    

    where wb is my object of webView

    0 讨论(0)
  • 2020-11-28 06:57

    I had a similar problem.... and later i found that the text box on the web page that my web view shown was disabled.

    Check this if the page has same problem in browser?

    0 讨论(0)
  • 2020-11-28 06:57

    I was having the exact same problem none of the above solutions worked for me. After ages of trying i finally found the problem.

    Some of the various web pages I was rendering with WebView didn't fit properly into the Web view and as a result a div (or some other html component ) were being invisibly laid over the input fields. Although the input fields appeared selected when touched, they would not allow text input (even if i did manage to get the soft keyboard up using the track ball).

    So the solution.

    WebView.getSettings().setUseWideViewPort(true);
    

    This won't completely stop the issue, but makes the view more like a PC browser which sites are designed for. Less change of the overlay.

    Hope this helps you.

    0 讨论(0)
  • 2020-11-28 06:57

    For making it easy, and as the other solutions have issues working on all devices or in all condition, I'm always using a small hack to overcome this issue without touching the code, just add any hidden editText to the layout contains the webView that will grant the focus to the whole view automatically and you will not have to worry about the webView text fields anymore:

    <EditText
        android:id="@+id/kb_holder"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:inputType="text"
        android:maxLines="1"
        android:visibility="gone" /> 
    

    So, the whole layout would be like:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <EditText
            android:id="@+id/kb_holder"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:inputType="text"
            android:maxLines="1"
            android:visibility="gone" />
    
        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </FrameLayout>
    
    0 讨论(0)
提交回复
热议问题