Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - show keyboard programmatically [duplicate]

I have an EditText field which is disabled at the beginning.

I would like to set it to enabled, put the cursor on it and the keyboard should be visible.

I tried the following code and all works - only the keyboard will not be shown.

@Override protected void onCreate(Bundle savedInstanceState{     editText.setEnabled(true);     editText.requestFocus();     getSystemService(Context.INPUT_METHOD_SERVICE);     imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); } 
like image 937
Ghost108 Avatar asked Dec 16 '15 07:12

Ghost108


1 Answers

For hiding keyboard:

InputMethodManager imm = (InputMethodManager)getSystemService(   Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); 

For Showing keyboard:

InputMethodManager imm = (InputMethodManager)   getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
like image 90
Nabeel K Avatar answered Oct 05 '22 03:10

Nabeel K