In an Android app, whenever the activity launches, the textbox gets the focus and the soft keyboard pops up automatically. I have tried to stop this by using following line
You can use the following line of code to make sure the keyboard only pops up when a user clicks into an EditText
Java
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Kotlin
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
And
You need to add
android:windowSoftInputMode="adjustResize"
to your activity tag in the AndroidManifest.xml file.
Does the following work?
// Find editor
EditText editWindowInstance = this.findViewById(R.id.MyEditWindow);
// close soft keyboard
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(editWindowInstance.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
You can put this code in your Activity.onCreate: this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
But I found that the most reliable and clean way was to simply set the focus onto to a different view, in your activity XML Layout
<Button
android:id="@+id/mybutton">
<requestFocus />
</Button>
This will work perfectly, try this
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
And add the following to your manifest.
android:windowSoftInputMode="stateHidden|adjustResize"
cheers enjoy coding....
The following code works for me
((InputMethodManager) iClockActivity
.getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(textView, 0);
I know this is old but maybe it will help someone in the future...
I haven't seen anyone suggest "stateHidden"
From the Android docs - android:windowSoftInputMode
Your manifest file would look like:
<activity
...
android:windowSoftInputMode="stateHidden|adjustResize"
...
>