隐藏软键盘

public class SoftKeyboardUtil { /** * 隐藏软键盘(只适用于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(), InputMethodManager.HIDE_NOT_ALWAYS); } } }

posted @ 2017-03-30 08:55  请叫我码农怪蜀黍  阅读(137)  评论(0编辑  收藏  举报