Monday, May 29, 2017

Webview has focus but virtual keyboard doesn't show

Leave a Comment

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.

2 Answers

Answers 1

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

best of luck!!!

Answers 2

Hello Try changing this in your manifest

<activity             android:name=".ActivityName"             android:windowSoftInputMode="adjustResize"             android:screenOrientation="portrait"></activity> 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment