Home » Android » How to open Keyboard on Button click in android?

How to open Keyboard on Button click in android?

Posted by: admin June 15, 2020 Leave a comment

Questions:

How can I open Keyboard on Button click in android?

What I want to be like this:

enter image description here

How to&Answers:

Please try this

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

Answer:

InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);

imm.showSoftInput(view, flags)

an example may be:

InputMethodManager imm = (InputMethodManager) RouteMapActivity.this
    .getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mapView, InputMethodManager.SHOW_IMPLICIT);

Answer:

Write this code inside the Button click event to TOGGLE the keyboard:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);