How to stop EditText from gaining focus at Activity startup in Android

后端 未结 30 2760
别那么骄傲
别那么骄傲 2020-11-21 06:40

I have an Activity in Android, with two elements:

  1. EditText
  2. ListView

When my Activity

30条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 07:30

    Is the actual problem that you just don't want it to have focus at all? Or you don't want it to show the virtual keyboard as a result of focusing the EditText? I don't really see an issue with the EditText having focus on start, but it's definitely a problem to have the softInput window open when the user did not explicitly request to focus on the EditText (and open the keyboard as a result).

    If it's the problem of the virtual keyboard, see the AndroidManifest.xml element documentation.

    android:windowSoftInputMode="stateHidden" - always hide it when entering the activity.

    or android:windowSoftInputMode="stateUnchanged" - don't change it (e.g. don't show it if it isn't already shown, but if it was open when entering the activity, leave it open).

提交回复
热议问题