How to keep soft keyboard from opening on activity launch in Android?

后端 未结 7 1822
Happy的楠姐
Happy的楠姐 2020-12-12 21:31

In an Android app, whenever the activity launches, the textbox gets the focus and the soft keyboard pops up automatically. I have tried to stop this by using following line

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 21:51

    You can put this code in your Activity.onCreate: this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    But I found that the most reliable and clean way was to simply set the focus onto to a different view, in your activity XML Layout

    
    

提交回复
热议问题