How to remove auto focus/keyboard popup of a field when the screen shows up?
Solution 1
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);
or
set activity property in manifest file as below in the application tag
android:windowSoftInputMode="stateHidden"
Solution 2
go to your application manifest file, and write this line for that activity you want to disable auto keyboard pop-up.
android:windowSoftInputMode="stateHidden"
Solution 3
To programatically not have the keyboard displayed, but the default widget still recieve focus call:
getWindow().setSoftInputMode(WindowManager.
LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
in onResume()
Solution 4
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
call the above method inside onCreate().It prevent softKeyboard to show unless user select EditText by
tapping or clicking.
or simply add android:windowSoftInputMode="stateHidden"
in Activity tag in Manifest.xml
Solution 5
This is usually a mess. The first thing I try is try to steal the focus with another view via . You also have to have the focusable and focusableInTouchMode.
<TextView
...
android:focusable="true"
android:focusableInTouchMode="true">
<requestFocus/>
</TextView>
Related videos on Youtube
Pentium10
Backend engineer, team leader, Google Developer Expert in Cloud, scalability, APIs, BigQuery, mentor, consultant. To contact: message me under my username at gm ail https://kodokmarton.com
Updated on July 08, 2022Comments
-
Pentium10 almost 2 years
I have a screen where the first field is an EditText, and it gains the focus at startup, also popups the numeric input type, which is very annoying
How can I make sure that when the activity is started the focus is not gained, and/or the input panel is not raised?
-
Pentium10 almost 14 yearsI've tried that but doesn't work. I called
.requestFocus();
on a button, and still the keyboard popups. -
Peter Lang almost 12 yearsWelcome to StackOverflow! This is not like other forums, if you want to change your answer, just click the
edit
link and make your changes. And please try to format your code by selecting your code and using the Code Sample button{}
or pressingCtrl+K
. -
Jeff Muir over 6 yearsSetting the android:windowSoftInputMode in AndroidManifest.xml file can be ORed with other values. Mode typically implies single values but in this case, the value is a collection of flags. Description of values:
Formats: flag Values: adjustNothing, adjustPan, adjustResize, adjustUnspecified, stateAlwaysHidden, stateAlwaysVisible, stateHidden, stateUnchanged, stateUnspecified, stateVisible Specify the default soft-input mode for the main window of this activity. A value besides "unspecified" here overrides any value in the theme.
-
glez about 6 yearsDidn't work for me. I put it in activity_main.xml. This worked perfect when I put it in onCreate(). getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
-
Alberto M almost 6 yearsthoughts can be added as comments