Android设置EditText输入时弹出的键盘可以改为登录/搜索等

有时候页面内容比较多,我希望某个EditText输入后可以直接点击键盘上的某个按钮就行一些操作,那就要设置相关的属性;

1. 属性设置

1.设置单行: android:singleLine="true"

2. 设置按键类型:android:imeOptions="actionSend"

类型:

(1)actionUnspecified未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED效果:

(2)actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE效果:

(3)actionGo去往,对应常量EditorInfo.IME_ACTION_GO 效果:

(4)actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH效果: 

(5)actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND效果:

(6)actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT效果:

(7)actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE效果:

 

3. 设置按键文字:android:imeActionLabel="注册"

            <EditText
                    android:id="@+id/edit_password"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dp_50"
                    android:layout_marginLeft="@dimen/dp_20"
                    android:maxLength="20"
                    android:paddingLeft="@dimen/dp_10"
                    android:password="true"
                    android:textColor="@color/white"
                    app:borderColor="#00f0ff"
                    app:borderWidth="@dimen/dp_1"
                    app:radius="@dimen/dp_5"
                    android:singleLine="true"
                    android:imeOptions="actionSend"
                    android:imeActionLabel="登录"
                     />

2. 事件设置:

 edit_password.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (edit_password.getImeOptions() == EditorInfo.IME_ACTION_SEND) {

                    //添加需要处理的代码
                   // if (checkEdt()) {
                   //     login(phone, password);
                   // }

                   //记得要返回true,防止多次调用
                    return true;
                }
                return false;
            }
        });

记得要返回true,防止多次调用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章