一、自动弹出关闭键盘
//弹出键盘
private void showKeyboard(View view){
InputMethodManager imm= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm != null){
view.requestFocus();
inputMethodManager.showSoftInput(view, 0);
}
}
//关闭键盘
private void closeKeyboard(View view) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if(imm != null)
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
//切换键盘的弹出和隐藏
public static void toggleSoftInput(View view){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null)
imm.toggleSoftInput(0,0);
}
二、Android:windowSoftInputMode属性设置
- stateUnspecified
- stateUnchanged
- stateHidden
- stateAlwaysHidden
- stateVisible
- stateAlwaysVisible。
- adjustUnspecified
- adjustResize
- adjustPan。