Android填坑之旅(第三篇) 关于Android 最有效的隐藏软键盘方法

来源:互联网 发布:知己知彼软件破解版 编辑:程序博客网 时间:2024/05/16 00:54

本文转自:https://juejin.im/post/58d8ccb45c497d005702dae6

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);        }    }}
0 0
原创粉丝点击