0

I tried this : Tapping form field in WebView does not show soft keyboard

My setup function called in on create is

public void begin() {
    EditText t = (EditText) findViewById(R.id.ccentry);
    t.setSelected(false);
    t.clearFocus();

    final WebView webview = (WebView) findViewById(R.id.webview);

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webview.addJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer");

    View.OnTouchListener l =  new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    Log.v("biscuit-focus", "focus");
                    if (!v.hasFocus()) {
                        Log.v("biscuit-focus-down", "focusDOWN");
                        v.requestFocus(View.FOCUS_DOWN);
                    }
                    break;
            }
            return false;
        }
    };

    webview.setOnTouchListener(l);

    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            printDebug();
            webview.requestFocus(View.FOCUS_DOWN);
            if (!madeTimer) {
                madeTimer = true;
                timer = new Timer();

                timer.scheduleAtFixedRate(new TimerTask() {
                    public void run() {
                        handler.obtainMessage(1).sendToTarget();
                    }
                }, 5000, 5000);


            }
        }
    });

    webview.loadUrl("myapp.com");
}

When I scroll down and tap the text field, I can get USB keyboard entry. The biscuit-focus log shows but not bicuit-focus-down.

This is on a Pine64 running Lollipop.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
quantumpotato
  • 9,637
  • 14
  • 70
  • 146

2 Answers2

0

Hello Try changing this in your manifest

<activity
            android:name=".ActivityName"
            android:windowSoftInputMode="adjustResize"
            android:screenOrientation="portrait"></activity>
Pratik Vyas
  • 644
  • 7
  • 20
0

You can add the codes:

it will works 100%.

 webview.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            view.removeOnPreDrawListener(this);
            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

            // !Pay attention to return `true`
            // Chet Haase told to 
            return true;
        }
    });

or

webview.requestFocus(View.FOCUS_DOWN);

best of luck!!!

  • Hello, I had to change view to webview becuase I have no instance variable named "view". Then I get: "cannot resolve removeOnPreDrawListener" – quantumpotato May 27 '17 at 16:40
  • @quantumpotato, Hello try now. Hopefully will works. –  May 28 '17 at 03:21
  • it looks like you changed view to webview. Please read m;y second sentence. .getViewTreeObserver() or addOnPreDrawListener are not found – quantumpotato May 29 '17 at 00:26
  • change view.removeOnPreDrawListener(this); ==> . mWebView.getViewTreeObserver().removeOnPreDrawListener(this); – DeepakPanwar Jul 26 '18 at 06:18