public class KeyboardUtils {
private KeyboardUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* 隐藏软键盘
*
* @param activity The activity.
*/
public static void hideSoftInput(final Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (imm == null) return;
View view = activity.getCurrentFocus();
if (view == null) view = new View(activity);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
/**
* 判断软键盘是否可见
*
* @param activity The activity.
* @return {@code true}: yes<br>{@code false}: no
*/
public static boolean isSoftInputVisible(final Activity activity) {
return isSoftInputVisible(activity, 200);
}
public static boolean isSof
Android工具类之Keyboard
最新推荐文章于 2021-07-13 14:00:13 发布
本文详细探讨了Android中处理软键盘的相关问题,包括如何自动隐藏和显示键盘,以及在应用交互中键盘对布局的影响。通过自定义工具类,开发者可以更好地控制键盘的行为,提升用户体验。
摘要由CSDN通过智能技术生成