public final class KeyBoardUtil { public KeyBoardUtil() { } public static void showKeyBoard(Context context, EditText editText) { InputMethodManager inputMethodManager = (InputMethodManager)context.getSystemService("input_method"); inputMethodManager.showSoftInput(editText, 2); inputMethodManager.toggleSoftInput(2, 1); } public static void hideKeyBoard(Activity context) { View view = context.getCurrentFocus(); if(view != null) { InputMethodManager inputMethodManager = (InputMethodManager)context.getSystemService("input_method"); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 2); } } public static boolean isShownKeyBoard(Activity activity) { View view = activity.getWindow().peekDecorView(); if(view == null) { return false; } else { InputMethodManager inputMethodManager = (InputMethodManager)activity.getSystemService("input_method"); return inputMethodManager.isActive() && activity.getWindow().getCurrentFocus() != null; } } }
android KeyBoardUtil
最新推荐文章于 2024-09-01 09:29:50 发布
