小键盘

/**
 * 显示软键盘
 */
public void showKeyboard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(getWindow().getDecorView(), InputMethodManager.SHOW_FORCED);
}

/**
 * 显示软键盘
 */
public void showKeyboard(EditText editText) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInputFromInputMethod(editText.getWindowToken(), 0);
}

/**
 * 点击屏幕隐藏软键盘
 *
 * @param event
 * @return
 */
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (getCurrentFocus() != null && getCurrentFocus().getWindowToken() != null) {
            manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
    return super.onTouchEvent(event);
}
private InputMethodManager manager;
onCreate里需要写

manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
阅读更多

没有更多推荐了,返回首页