Wednesday, 4 September 2013

Disable or Enable the soft keyboard

Because the tendency of new mobile devices is getting the screen bigger and the device thinner, there are less devices which has the hard keyboard by time passing. Thus the soft keyboard is commonly used.

Here is some code to enable or disable it automatically:

Enable the soft keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
EditText editText = (EditText)findItemById(R.id.editText);
editText.requestFocus();
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

Disable the soft keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
EditText editText = (EditText)findItemById(R.id.editText);

editText.clearFocus();


imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

Source:

No comments:

Post a Comment