Android method to detect whether the keyboard is displayed and hidden~~
There are many articles on the hiding and display of keyboards in Android. Today, the company's project needs not only require keyboard hiding and display, but also require checking the status of the keyboard. Here is a simple implementation example for your reference:
Implementation code:
package ; import ; import ; import ; /** * System input method keyboard detection tool * * @author yuyh * */ public class IMEUtil { /** * Hide the keyboard * @param context */ public static void hideIme(Activity context) { if (context == null) return; final View v = ().peekDecorView(); if (v != null && () != null) { InputMethodManager imm = (InputMethodManager) (Activity.INPUT_METHOD_SERVICE); ((), 0); } } /** * Check whether the system keyboard is displayed * @param context * @return */ public static boolean isSysKeyboardVisiable(Activity context) { final View v = ().peekDecorView(); if (v != null && () != null) { return true; } return false; } }
Thank you for reading, I hope it can help you. Thank you for your support for this site!