隐藏软键盘方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Lemon_husky/article/details/83549335
/**
 * 隐藏键盘
 *
 * @param context
 * @param view
 */
public static void hideSoftInput(Context context, View view) {
    InputMethodManager imm = (InputMethodManager) IMApp.getAppContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (view == null) {
        imm.toggleSoftInput(0, InputMethodManager.RESULT_HIDDEN);
    } else {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘
    }
}

/**
 * 判断输入法是否显示
 *
 * @param context
 * @return
 */
public static boolean getSoftInputState(Activity context) {
    return context.getWindow().getAttributes().softInputMode == WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED;
}

猜你喜欢

转载自blog.csdn.net/Lemon_husky/article/details/83549335