5

I need some help with showing/allowing the keyboard to show and input.

My basic app has a main screen with buttons, on button click it opens a webview, one of my buttons opens a webview to an HTML page with an input form. When you click on an input field, the keyboard does not show and when you use the hardware keyboard on the emulator it just brings up chinese suggestions and does not input any text.

Brent Hacker
  • 394
  • 2
  • 8
  • 26

3 Answers3

8

As Brent suggested, following line will serve the purpose -

webView.requestFocus(View.FOCUS_DOWN);

this happens because on page loading webpage loses its focus so this line just bring the focus back to page.

For those who end up at this question, A detailed discussion on this topic is here

Community
  • 1
  • 1
Darpan
  • 5,623
  • 3
  • 48
  • 80
5

None of these worked for me. But applying all-app webViewStyle to the webview fixed everything.

The issue was fixed using style="?android:attr/webViewStyle" in the webview definition, like this:

<?xml version="1.0" encoding="utf-8"?>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/webViewStyle"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Aliya
  • 1,168
  • 12
  • 17
  • I had to add this after extending and overriding some WebView methods. Specifically I added a context menu for links. For some reason this stopped the keyboard from showing, very strange, maybe I am missing something. – micwallace Jul 13 '16 at 10:06
3

I solved this issue myself with further googling I have my webview declared as

WebView wb;

When I launch my webview (in my case a button click) you'll pass the requestFocus statement...

public void onMyButtonClick01(View view)  
{  
    Toast.makeText(this, "Haha!", Toast.LENGTH_SHORT).show(); 
    wb = new WebView(this);
    wb.loadUrl("http://www.test.html");
    setContentView(wb);  
    wb.requestFocus(View.FOCUS_DOWN);
}       
Brent Hacker
  • 394
  • 2
  • 8
  • 26