How to clear focus for EditText?

前端 未结 8 1088
滥情空心
滥情空心 2021-01-30 12:54

I have an activity with a search box (EditText) on the top, and a ListView below. Whenever the activity starts, the EditText always has focus and bring up the keybo

8条回答
  •  时光说笑
    2021-01-30 13:38

    Set in your parent layout next attributes:

    
    

    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.

提交回复
热议问题