How to set focus on a view when a layout is created and displayed?

后端 未结 15 1073
Happy的楠姐
Happy的楠姐 2020-12-02 15:07

Currently, I have a layout which contains a Button, a TextView and an EditText. When the layout is displayed, the focus will be automa

15条回答
  •  有刺的猬
    2020-12-02 15:38

    You can start by adding android:windowSoftInputMode to your activity in AndroidManifest.xml file.

    
    

    This will make the keyboard to not show, but EditText is still got focus. To solve that, you can set android:focusableInTouchmode and android:focusable to true on your root view.

    
        
        
        

    The code above will make sure that RelativeLayout is getting focus instead of EditText

提交回复
热议问题