监听键盘右下角按钮点击事件

来源:互联网 发布:js如何往html页面传值 编辑:程序博客网 时间:2024/05/13 18:46

1、布局文件XML添加EditText:

<EditText    android:id="@+id/etPhoneNumber"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:singleline="true"    android:imeoptions="actionSearch"/>

注意:android:imeOptions起作用,必须加上android:inputType属性或者android:singleLine="true"属性。

imeOptions样式有:
actionNone : 回车键,按下后光标到下一行
actionGo : Go
actionSearch : 放大镜
actionSend : Send
actionNext : Next
actionDone : Done,确定/完成,隐藏软键盘,即使不是最后一个文本输入框

2、添加监听事件:

etPhoneNumber.setOnEditorActionListener(new TextView.OnEditorActionListener() {            @Override            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {                switch (actionId) {            case EditorInfo.IME_ACTION_NONE:                Toast.makeText(mContext, "点击-->NONE", Toast.LENGTH_SHORT).show();                break;            case EditorInfo.IME_ACTION_GO:                Toast.makeText(mContext, "点击-->GO", Toast.LENGTH_SHORT).show();                break;            case EditorInfo.IME_ACTION_SEARCH:                Toast.makeText(mContext, "点击-->SEARCH", Toast.LENGTH_SHORT).show();                break;            case EditorInfo.IME_ACTION_SEND:                Toast.makeText(mContext, "点击-->SEND", Toast.LENGTH_SHORT).show();                break;            case EditorInfo.IME_ACTION_NEXT:                Toast.makeText(mContext, "点击-->NEXT", Toast.LENGTH_SHORT).show();                break;            default:                break;            }        });


0 0
原创粉丝点击