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
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();");
}
});
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
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?
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.
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>