Android 软键盘那点事

来源:互联网 发布:sql select count 编辑:程序博客网 时间:2024/06/13 03:36

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;            }        });
0 0
原创粉丝点击