Sometimes, when developing any application in android, we need to hide keyboard at start-up screen if our screen holds editable views like EditText, Spinner etc which have focus on them. Until user touch on one of editable view, we need to hide keyboard.
To hide soft keyboard, use following short of code in your application. This code will hide soft keyboard from your screen.
To Hide Soft Keyboard,
InputMethodManager imm = InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(FOCUSABLE_VIEW.getWindowToken(), 0);
|
Here, "FOCUSABLE_VIEW" can be any view which is visible on screen like
editText = (EditText) findViewById(R.id.editText);
InputMethodManager imm = InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
|
To Show Soft Keyboard,
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(EDITABLE_VIEW, InputMethodManager.SHOW_IMPLICIT);
|
Here, "EDITABLE_VIEW
" can be any view which has focus on screen like
editText = (EditText) findViewById(R.id.editText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText , InputMethodManager.SHOW_IMPLICIT);
|