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,防止多次調用

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