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

后端 未结 15 1240
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:34

    to change the focus make the textView in xml focusable

    
    

    and in java in on create

    textView.requestFocus();

    or simply hide the keyboard

    public void hideKeyBoard(Activity act) {
        act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        InputMethodManager imm = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE);
    }
    

提交回复
热议问题