public class KeybordS {
/**
* 打开软键盘
*
* @param mEditText
* @param mContext
*/
public static void openKeybord(EditText mEditText, Context mContext) {
InputMethodManagerimm = (InputMethodManager) mContext
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
}
/**
* 关闭软键盘
*
* @param mEditText输入框
* @param mContext上下文
*/
public static void closeKeybord(EditText mEditText, Context mContext) {
InputMethodManagerimm = (InputMethodManager) mContext
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(),0);
}
/**
* 判断当前软键盘是否打开
*
* @param activity
* @return
*/
public static boolean isSoftInputShow(Activity activity) {
// 虚拟键盘隐藏 判断view是否为空
Viewview = activity.getWindow().peekDecorView();
if (view !=null) {
// 隐藏虚拟键盘
InputMethodManagerinputmanger = (InputMethodManager) activity
.getSystemService(Activity.INPUT_METHOD_SERVICE);
// inputmanger.hideSoftInputFromWindow(view.getWindowToken(),0);
return inputmanger.isActive() && activity.getWindow().getCurrentFocus() !=null;
}
return false;
}
}
网友评论