Automatic popping up keyboard on start Activity

后端 未结 19 991
醉梦人生
醉梦人生 2020-11-28 23:05

I got a relative simple question. I have an activity with a lot of EditText\'s in them. When I open the activity it automatically focusses to the first EditText and displays

相关标签:
19条回答
  • 2020-11-28 23:37

    I have several implementations described here, but now i have added into the AndroidManifest.xml for my Activity the property:

    android:windowSoftInputMode="stateAlwaysHidden"
    

    I think this is the easy way even if you are using fragments.

    "stateAlwaysHidden" The soft keyboard is always hidden when the activity's main window has input focus.

    0 讨论(0)
  • 2020-11-28 23:40

    android:windowSoftInputMode="stateHidden|adjustResize"

    Working fine

    0 讨论(0)
  • 2020-11-28 23:42

    If you have another view on your activity like a ListView, you can also do:

    ListView.requestFocus(); 
    

    in your onResume() to grab focus from the editText.

    I know this question has been answered but just providing an alternative solution that worked for me :)

    0 讨论(0)
  • 2020-11-28 23:44

    Use this attributes in your layout tag in XML file:

    android:focusable="true"
    android:focusableInTouchMode="true"
    

    As reported by other members in comments it doesn't works on ScrollView therefore you need to add these attributes to the main child of ScrollView.

    0 讨论(0)
  • 2020-11-28 23:44

    Interestingly, this documentation https://developer.android.com/training/keyboard-input/visibility.html states that when an activity starts and focus is given to a text field, the soft keyboard is not shown (and then goes on to show you how to have the keyboard shown if you want to with some code).

    On my Samsung Galaxy S5, this is how my app (with no manifest entry or specific code) works -- no soft keyboard. However on a Lollipop AVD, a soft keyboard is shown -- contravening the doc given above.

    If you get this behavior when testing in an AVD, you might want to test on a real device to see what happens.

    0 讨论(0)
  • This occurs when your EditText automatically gets Focus as when you activity starts. So one easy and stable way to fix this, is simply to set the initial focus to any other view, such as a Button etc.

    You can do this in your layout XML, no code required..

    0 讨论(0)
提交回复
热议问题