How to remove auto focus/keyboard popup of a field when the screen shows up?

AndroidKeyboardPopupAndroid Softkeyboard

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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 - Android

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 - Android

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 - Android

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 - Android

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>

Solution 6 - Android

Have another view grab focus. By default, the first focusable View will get focus when a layout is inflated. You can request focus on a different View via XML:

<TextView
    android:layout_width="wrap_parent"
    android:layout_height="wrap_content"
    android:text="Some other view">

    <requestFocus />
</TextView>

This works for any View.

If you want to do it programmatically, you can use view.requestFocus().

Solution 7 - Android

Adding android:windowSoftInputMode="stateHidden" to your Activity in manifest only hides the keyboard when you are launching the activity, or as Google says

> When the user affirmatively navigates forward to the activity, rather > than backs into it because of leaving another activity

To hide the keyboard also when user presses the back button and moves back to your activity from some other activity, use android:windowSoftInputMode="stateAlwaysHidden"

Solution 8 - Android

if(getWindow().getAttributes().softInputMode==WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED)
{
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}

Solution 9 - Android

have not tried this nor am i near my programming computer, but I would suspect programmatically sending focus to the parent view or something of that nature could do the trick - thats more likely a workaround than a solution, but again not able to test it just a thought

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPentium10View Question on Stackoverflow
Solution 1 - AndroidMitul NakumView Answer on Stackoverflow
Solution 2 - Androidsm.euroView Answer on Stackoverflow
Solution 3 - AndroiddanmuxView Answer on Stackoverflow
Solution 4 - AndroidXar-e-ahmer KhanView Answer on Stackoverflow
Solution 5 - AndroidurSusView Answer on Stackoverflow
Solution 6 - AndroidJason RobinsonView Answer on Stackoverflow
Solution 7 - AndroidDevansh MauryaView Answer on Stackoverflow
Solution 8 - Androidpaul LiangView Answer on Stackoverflow
Solution 9 - AndroidBenView Answer on Stackoverflow