//隐藏软键盘
public class KeyBoardUtils {
/**
* 隐藏软键盘(只适用于Activity,不适用于Fragment)
*/
public static void hideSoftKeyboard(Activity activity) {
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
/**
* 隐藏软键盘(可用于Activity,Fragment)
*/
public static void hideSoftKeyboard(Context context, List<View> viewList) {
if (viewList == null) return;
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
for (View v : viewList) {
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), InputMeth
Android隐藏软键盘及软键盘弹出与关闭监听
最新推荐文章于 2024-07-04 16:13:56 发布
本文详细介绍了在Android应用中如何隐藏和显示软键盘,并提供了监听软键盘弹出与关闭的方法,帮助开发者优化用户交互体验。
摘要由CSDN通过智能技术生成