Soft keyboard is not displayed in input field in WebView

I created my own WebView and set the WebChromeClient and WebViewClient objects. When I launch this WebView, the HTML form fields react when I touch them (the cursor appears), but they are not selected, and the soft keyboard does not start. If I use the trackball to select a form and press it, a keyboard will appear.

I tried calling myWebview.requestFocusFromTouch() as this answer , but it returns false and does not help.

+52
android webview
Nov 16 '10 at 23:55
source share
5 answers

http://code.google.com/p/android/issues/detail?id=7189

Here is a correction if others were not clear.

 webview.requestFocus(View.FOCUS_DOWN); 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; } }); 
+94
Feb 12 '11 at 9:03
source share

Agreed 10% with the answer Dv_MH. However, the attached class was a bit excessive. All I had to do was extend the WebView and return true for onCheckIsTextEditor ()

 import android.content.Context; import android.util.AttributeSet; import android.webkit.WebView; public class LiveWebView extends WebView { public LiveWebView(Context context) { super(context); } public LiveWebView(Context context, AttributeSet attrs) { super(context, attrs); } public LiveWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onCheckIsTextEditor() { return true; } } 

From there, I was able to use it as a regular WebView (even in Dialogs).

Alternatively, with less code:

 WebView web = new WebView(context) { @Override public boolean onCheckIsTextEditor() { return true; } }; 
+24
Jul 19 '14 at 10:12
source share

IMPORTANT I spent hours searching for this, and I solved it by making sure that the parent layout that extends the “ViewGroup” has no property

android: descendantFocusability = "blocksDescendants" that prevent the focus of the child layout

OR Add android: focusable = "true" for web browsing

+4
May 17 '16 at 7:56 a.m.
source share

The answer to AndroidChen didn't work for me at all, but I was looking for the provided link ( http://code.google.com/p/android/issues/detail?id=7189 ) and I found the following class, it works fine (Android Froyo on HTC Bravo), not just text, but all buttons, redirects, etc., everything works fine: D

 class LiveWebView extends WebView { Context mContext; public LiveWebView(Context context, String URL) { super(context); mContext = context; setWebViewClient(URL); } @Override public boolean onCheckIsTextEditor() { return true; } @SuppressLint("SetJavaScriptEnabled") boolean setWebViewClient(String URL) { setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY); setFocusable(true); setFocusableInTouchMode(true); requestFocus(View.FOCUS_DOWN); WebSettings webSettings = getSettings(); webSettings.setSavePassword(false); webSettings.setSaveFormData(false); webSettings.setJavaScriptEnabled(true); webSettings.setSupportZoom(false); webSettings.setUseWideViewPort(false); 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; } }); this.setWebViewClient(new WebViewClient() { ProgressDialog dialog = new ProgressDialog(mContext); @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { loadUrl(url); return true; } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Toast.makeText(mContext, "Oh no! " + description, Toast.LENGTH_SHORT).show(); } public void onPageStarted(WebView view, String url, Bitmap favicon) { if (dialog != null) { dialog.setMessage("Loading..."); dialog.setIndeterminate(true); dialog.setCancelable(true); dialog.show(); } } public void onPageFinished(WebView view, String url) { if (dialog != null) { dialog.cancel(); } } }); this.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { // Activities and WebViews measure progress with different scales. // The progress meter will automatically disappear when we reach 100% } @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { result.confirm(); return true; } }); loadUrl(URL); return true; } } 

and then, to create a webview in a dialog box, I wrote this code

 AlertDialog.Builder alert = new AlertDialog.Builder(M_PaymentOptions.this); alert.setNegativeButton("Back to Payment Options", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) {} }); alert.setTitle("BarclayCard Payment"); LiveWebView liveWevViewObject = new LiveWebView(M_PaymentOptions.this, redirecturl); alert.setView(liveWevViewObject); alert.show(); 
+3
Apr 08 '13 at 18:18
source share

Just add invisible EditText to WebView

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="invisible" /> <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent"/> 

All these focus-related solutions didn't work on my Samsung Note 3 / Android 5.0

+1
Oct. 16 '17 at 7:53 on
source share



All Articles