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);