Android工具类系列-KeyBoardUtil

来源:互联网 发布:妩媚知乎 编辑:程序博客网 时间:2024/05/16 05:51

原文地址:
http://blog.csdn.net/lmj623565791/article/details/38965311

主要是打开和关闭软键盘

package org.yxm.android.utils;import android.content.Context;import android.view.inputmethod.InputMethodManager;import android.widget.EditText;/** * Created by yxm on 16-6-23. */public class KeyBoardUtil {    /**     * 打卡软键盘     *     * @param mEditText 输入框     * @param mContext  上下文     */    public static void openKeybord(EditText mEditText, Context mContext) {        InputMethodManager imm = (InputMethodManager) mContext                .getSystemService(Context.INPUT_METHOD_SERVICE);        imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,                InputMethodManager.HIDE_IMPLICIT_ONLY);    }    /**     * 关闭软键盘     *     * @param mEditText 输入框     * @param mContext  上下文     */    public static void closeKeybord(EditText mEditText, Context mContext) {        InputMethodManager imm = (InputMethodManager) mContext                .getSystemService(Context.INPUT_METHOD_SERVICE);        imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);    }}
0 0