EditText弹出的软键盘带搜索按钮

来源:互联网 发布:淘宝如何刷流量 编辑:程序博客网 时间:2024/06/01 09:10
在editText添加属性:
android:singleLine="true"android:imeOptions="actionSearch"


在当前activity的配置文件中(AndroidManifest.xml)添加属性

android:windowSoftInputMode="adjustPan"


最后在Activity监听edittext的

setOnEditorActionListener事件
/*** * 监听输入框是否点击了搜索 */etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {    @Override    public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {        if (i == EditorInfo.IME_ACTION_SEARCH) {            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);            imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);//关闭软键盘            searchProduct(etSearch.getText().toString());            return true;        }        return false;    }});


阅读全文
0 0