android 中显示和隐藏键盘

/**
 * 隐藏软件盘方法的其中一种
 *
 * @param token
 */
protected void hideSoftInput(IBinder token)
{
    if (token != null)
    {
        InputMethodManager im = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        im.hideSoftInputFromWindow(token,
                InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
/**
 * EditText获取焦点并显示软键盘
 */
public static void showSoftInputFromWindow( ClearEditText editText) {
    editText.requestFocus();
    InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.toggleSoftInput(0,InputMethodManager.SHOW_FORCED);

}

猜你喜欢

转载自blog.csdn.net/w3812127/article/details/78331012