Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add done button on a keypad for android web view?

Before I made a native android app which contains a number input. when you click in it numeric keyboard of android pops up which has done button which hides keypad after clicking done button. but now i have made another similar app but it contains WebView so it is a website created using html,JavaScript, css etc. which has <input type ="number"/> and again numeric keypad of android pops up but no done button in it. it looks like the webview is handled by browser keypad. is it possible to add done button here?

like image 302
Kanwal Gill Avatar asked Oct 25 '25 04:10

Kanwal Gill


2 Answers

Please check out the following trick in Menifest.xml file for the activity which is having your webview

AndroidManifest.xml

<activity android:name="..."
  ...
   android:imeOptions="actionSend|flagNoEnterAction"
  ...
</activity>

Hope it works.

like image 116
Rakshit Sorathiya Avatar answered Oct 27 '25 19:10

Rakshit Sorathiya


Sharing code how i am detecting EditText in Webview

 mWebView = (MyWebView) findViewById(R.id.webview);
    mWebView.setOnTouchListener(new View.OnTouchListener() { 
        @Override
        public boolean onTouch(View v, MotionEvent event) {

        WebView.HitTestResult hr = ((WebView)v).getHitTestResult();
        int type = hr.getType();

          if (type == WebView.HitTestResult.EDIT_TEXT_TYPE) {
            //Calls When user touch edittext in webview
            //Open Keyboard with done button programatically

            return;
          }
      return false; 
     }
});

This is working fine for my task...Hope this help you also

like image 26
Lokesh Desai Avatar answered Oct 27 '25 19:10

Lokesh Desai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!