Edittext android automatic focus

后端 未结 3 1538
悲哀的现实
悲哀的现实 2021-01-11 20:01

I have an issue when the activity starts, android automatically places focus on the first edittext. How do I prevent android from doing that?

相关标签:
3条回答
  • 2021-01-11 20:22

    Have a look here

    Or you could just hide the keyboard, focus remains on the EditText upon starting the activity:

    android:windowSoftInputMode="stateHidden"
    
    0 讨论(0)
  • 2021-01-11 20:22

    use setFocusable (boolean focusable) to prevent. http://developer.android.com/reference/android/view/View.html#setFocusable(boolean)

    0 讨论(0)
  • 2021-01-11 20:26

    Three ways to solve this..

    1. Set these attributes to the parent..

    And now, when activity starts this layout getting default focus.

    Also we can remove focus from children views in runtime (e.g. after finishing child editing):

    findViewById(R.id.mainLayout).requestFocus(); or

    Look in the AndroidManifest.xml element.

    android:windowSoftInputMode="stateHidden"
    

    It always hide key board when entering the activity.

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