1.Activity加载时弹出输入法:EditText一定要是获得焦点的
//设置在activity启动的时候输入法默认是不开启的
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
//设置在activity启动的时候输入法默认是打开的
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
2.加载后 通过监听事件动态弹出
private void openKeyBord(EditText et,Context context){// 窗体第一次加载的时候,会闪开关输入法
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
et.setFocusable(true);
et.setFocusableInTouchMode(true);
et.requestFocus();// 获取交掉;searchPopEdit.clearFocus();// 失去焦点
imm.showSoftInput(et, InputMethodManager.SHOW_FORCED);
//// if (imm.isActive()) {// 键盘是否打开
// imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
private void closeKeyBord(EditText et,Context context){
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
}