参考代码:

public void setFocusEditTextAndShowSoftInput(final EditText editText){
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();//聚焦
        //判断当前editText是否绘制完成,绘制完成后再进行展示软键盘
        editText.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(editText, 0);//展示软键盘
            }
        });
    }

 

相关文章:

  • 2022-12-23
  • 2021-12-07
  • 2021-08-03
  • 2021-07-12
  • 2022-12-23
  • 2022-01-31
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2021-08-03
相关资源
相似解决方案