import android.app.Activity; import android.content.Context; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; public class KeyBordS { /** * 打开软键盘 * * @param mEditText * @param mContext */ public static void openKeybord(EditText mEditText, Context mContext) { InputMethodManager imm = (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) { InputMethodManager imm = (InputMethodManager) mContext .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0); } /** * 判断当前软键盘是否打开 * * @param activity * @return */ public static boolean isSoftInputShow(Activity activity) { // 虚拟键盘隐藏 判断view是否为空 View view = activity.getWindow().peekDecorView(); if (view != null) { // 隐藏虚拟键盘 InputMethodManager inputmanger = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); // inputmanger.hideSoftInputFromWindow(view.getWindowToken(),0); return inputmanger.isActive() && activity.getWindow().getCurrentFocus() != null; } return false; } }
软键盘Edittext监听开启和关闭工具类
最新推荐文章于 2021-05-26 05:19:08 发布