Android 软件盘回车键修改

来源:互联网 发布:js array 长度 编辑:程序博客网 时间:2024/06/07 10:32
在android中对EditText实现软件盘监听,当按下软键盘的时候,响应完成、发送、搜索或者其他事件。
1.在布局文件EditText中添加属性
android:singleLine="true"android:imeOptions="actionSearch"其中
把EditText的Ime Options属性设置成不同的值,Enter键上可以显示不同的文字或图案。
actionNone : 回车键,按下后光标到下一行
actionGo : Go,
actionSearch : 一个放大镜
actionSend : Send
actionNext : Next
actionDone : Done,隐藏软键盘,即使不是最后一个文本输入框然后在代码中设置对他的监听
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {            @Override            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {                if (actionId == EditorInfo.IME_ACTION_SEARCH) {                    Toast.makeText(MainActivity.this,"1111",Toast.LENGTH_SHORT).show();//                    performSearch();                    return true;                }                Toast.makeText(MainActivity.this,"222",Toast.LENGTH_SHORT).show();                return false;            }        });


0 0
原创粉丝点击