Android 软键盘那点事

Android 软键盘那点事

软键盘已显示则隐藏,反之亦然

InputMethodManager imm =(InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

监听软键盘的确定按钮,一般用来替换“确定”按钮

mEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    InputMethodManager imm =(InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    /*隐藏软键盘*/
                    if (imm.isActive()) {
                        imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
                    }
                    /*按确定后的其他操作*/
                    return true;
                }
                return false;
            }
        });

你可能感兴趣的:(Android)