9

How can I open Keyboard on Button click in android?

What I want to be like this:

enter image description here

tshepang
  • 12,111
  • 21
  • 91
  • 136
Girish Patel
  • 1,270
  • 4
  • 16
  • 30

3 Answers3

35

Please try this

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
Sandeep Kumar P K
  • 7,412
  • 6
  • 36
  • 40
10
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);
Felix
  • 88,392
  • 43
  • 149
  • 167
drooooooid
  • 1,574
  • 1
  • 11
  • 17
  • 1
    This is the correct answer. Other answers toggle the keyboard which is not desirable in many circumstances (i.e. we want to only SHOW the keyboard when user clicks the clear search field button, even if it is shown already) – Ashkan Sarlak Nov 30 '15 at 06:53
3

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);
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • @Paresh.....still not open keyboard on button click so please give me propre answer – Girish Patel Nov 10 '11 at 10:31
  • @PareshMayani if i want to open the keyboard of specific language.Suppose of click of button i want to open a Hindi Keyboard then what i have to do – Developer Jan 09 '14 at 09:03