How can I set the focus (and display the keyboard) on my EditText programmatically

后端 未结 13 823
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 02:22

I have a layout which contains some views like this:






&         


        
13条回答
  •  萌比男神i
    2020-11-28 02:39

    final EditText tb = new EditText(this);
    tb.requestFocus();
    tb.postDelayed(new Runnable() {
        @Override
        public void run() {
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.showSoftInput(tb, InputMethodManager.SHOW_IMPLICIT);
        }
    }, 1000);
    

提交回复
热议问题