Android设置EditText弹出软键盘

final EditText editText = findViewById(R.id.et);
editText.selectAll();   //默认选中EditText中的所有内容
editText.setFocusable(true);   //设置可以获取焦点
editText.setFocusableInTouchMode(true);     
editText.requestFocus();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
                   public void run() {
                       InputMethodManager inputManager =
                               (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                       inputManager.showSoftInput(editText, 0);
                   }
               },
        900);

在Popwindow中,EditText也是默认不弹键盘的,可以设置

final EditText editText = view.findViewById(R.id.et);
editText.setFocusable(true);
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Service.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

猜你喜欢

转载自blog.csdn.net/qq_30711091/article/details/83786883