/**
* 弹出软键盘
*/
et_username.requestFocus(); // edittext是一个EditText控件
Timer timer = new Timer(); // 设置定时器
timer.schedule(new TimerTask() {
@Override
public void run() { // 弹出软键盘的代码
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et_username, InputMethodManager.RESULT_SHOWN);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
}
}, 300); // 设置300毫秒的时长
/**
* 隐藏软键盘
*/
view = getWindow().peekDecorView();
if (view != null) {
InputMethodManager inputmanger = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
}