选择文本时,如何停止EditText显示键盘?

时间:2019-01-24 13:59:54

标签: java android android-studio

每次尝试选择一个文本时,它都会打开键盘。如何防止这种情况?

2 个答案:

答案 0 :(得分:1)

尝试

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

答案 1 :(得分:1)

点击编辑文本时,您需要隐藏键盘:

mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if ( hasFocus )
            {
                hideKeyBoard();
            }
        }
    });

和hideKeyboard方法:

private void hideKeyBoard()
{
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        if( imm != null )
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}