When there are one or more EditText in the activity, a soft keyboard automatically appears when the activity is launched, which hides some visible portion of the screen and we don't always have a requirement to automatically pop-up the soft input keyboard.
We can solve this by editing Manifest.xml file.
Add the following attribute inside the particular Activity tag in Manifest.xml file -
android:windowSoftInputMode="stateAlwaysHidden"
It will keep the Keyboard hidden when the activity is resumed.
or, in your Activity class call the following method -
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
You can also close a keyboard on any event like on button click by using InputMethodManager class by calling hideSoftInputFromWindow and passing the desired parameters -
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
0 Comment(s)