How to close and hide the Android software keyboard ?
In an application, when you wait for users input you must use EditText wigdets. When users end their inputs and click OK button, you would like close the Android software keyboard. It’s better than asking to users to close software keyboard themselves.
Use that snippet code :
EditText myEditText = (EditText) findViewById(R.id.myEditText); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
In other hand, you can want to hide all the time the software keyboard for some reasons (good or bad). To achieve that, there are 2 solutions :
1. First is linked to Android Manifest. Use the following attribute for your activity targeted :
android:windowSoftInputMode="stateHidden"
2. Second is achieved programmatically :
getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN );
Leave a Reply
You must be logged in to post a comment.