Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm in exactly the same boat, so if you ever found an ideal solution, I'd love to hear it.</p> <p>EDIT: Success! Or much better than before, anyway. I've deleted my old solution, since this one is better.</p> <p>As stated in <a href="https://stackoverflow.com/a/10536033/513038">https://stackoverflow.com/a/10536033/513038</a>, it turns out that loadData() hides the keyboard. <em>However</em>, I discovered that in the WebView's hideSoftKeyboard(), it checks the InputMethodManager to see if the webview is active, via imm.isActive(mWebView).</p> <p>So, if you switch focus to an EditText before loadData(), and switch back to the WebView immediately after, the keyboard sticks around! It briefly switches to upper-case, I think on returning focus to the webview, (actually, this doesn't always seem to happen; it depends) but it's a lot less noticeable than the keyboard flickering away and back.</p> <p>The gist of what needs to happen is as follows.</p> <p>Extend WebView. Give it an EditText field:</p> <pre><code>public EditText mFocusDistraction; </code></pre> <p>In the constructor, have the following lines:</p> <pre><code>mFocusDistraction = new EditText(context); addView(mFocusDistraction); </code></pre> <p>Then override loadUrl():</p> <pre><code>public void loadUrl(String s) { mFocusDistraction.requestFocus(); super.loadUrl(s); this.requestFocus(); } </code></pre> <p>That should get it working, basically. It's a bit buggy, though, so here's a more complete class:</p> <pre><code>import android.app.Activity; import android.content.Context; import android.util.AttributeSet; import android.webkit.WebView; import android.widget.EditText; public class WebViewMod extends WebView { public EditText mFocusDistraction; public Context mContext; public WebViewMod(Context context) { super(context); init(context); } public WebViewMod(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public WebViewMod(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); } public WebViewMod(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { super(context, attrs, defStyle, privateBrowsing); init(context); } public void init(Context context) { // This lets the layout editor display the view. if (isInEditMode()) return; mContext = context; mFocusDistraction = new EditText(context); mFocusDistraction.setBackgroundResource(android.R.color.transparent); this.addView(mFocusDistraction); mFocusDistraction.getLayoutParams().width = 1; mFocusDistraction.getLayoutParams().height = 1; } @Override public void loadUrl(final String url) { if (mContext instanceof Activity &amp;&amp; this.isFocused()) { ((Activity)mContext).runOnUiThread(new Runnable() { @Override public void run() { mFocusDistraction.requestFocus(); WebViewMod.super.loadUrl(url); WebViewMod.this.requestFocus(); } }); } else { super.loadUrl(url); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload