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