There is no focus cursor on the input field.

We have a Cordova android android app where custom inappbrowser is created with cordova web browser to show content. On Android lollipop devices, when the user selects the input field, the keyboard appears and the user can enter the test, but there is no cursor in the input field. This does not happen in pre lollipop. I tried under options, also it happens sporadically, sometimes I get focus but most of the time it doesn't work.

inAppWebView.getSettings().setJavaScriptEnabled(true);
inAppWebView.requestFocus(View.FOCUSABLES_TOUCH_MODE);

      

or

inAppWebView.requestFocus(View.FOCUSABLES_ALL);

      

or

inAppWebView.requestFocus(View.FOCUS_DOWN);

      

or

inAppWebView.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;
                }
            });

      

Any suggestions?

+3


source to share


3 answers


After much thought and effort going through the repo history, we finally nailed it and fixed it.

While initializing the plugin, we ran some javascript on the WebView. We are using 'evaluatingJavascript' to execute javascript (this works on Lollipop, not KitKat btw) but this somehow caused the side effect of the caret disappearing. After using 'loadUrl', it worked again.

In javascript, we added a custom attribute (HD_APP) to the window, so nothing that could cause this side effect. As you can see in the screenshot, the input is no longer identified with the ": focus" css.



Hope it helps.

comparison of css input of working example (left) and one without caret (right)

0


source


Although now probably a long-obsolete solution can be found at https://issues.apache.org/jira/browse/CB-11248

Basically, you need to change onPageFinished to



public void onPageFinished(WebView view, String url) {
  super.onPageFinished(view, url);
  view.clearFocus();
  view.requestFocus();

      

}

0


source


The problem that gave me the problem is what I called evaluateJavascript

before any page was loaded.

After I made sure my page was JS ready before submitting, the problem went away.

0


source







All Articles