android:imeOptions屬性詳解以及無效處理
軟鍵盤的Enter鍵默認顯示的是“完成”文本,我們知道按Enter建表示前置工作已經準備完畢了,要去什麼什麼啦。比如,在一個搜索中,我們輸入要搜索的文本,然後按Enter表示要去搜索了,但是默認的Enter鍵顯示的是“完成”文本,看着不太合適,不符合搜索的語義,如果能顯示“搜索”兩個字或者顯示一個表示搜索的圖標多好。事實證明我們的想法是合理的,Android也爲我們提供的這樣的功能。通過設置android:imeOptions來改變默認的“完成”文本。這裏舉幾個常用的常量值:
(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效果:
android:imeOptions=“flagNoExtractUi” //使軟鍵盤不全屏顯示,只佔用一部分屏幕 同時,
這個屬性還能控件軟鍵盤右下角按鍵的顯示內容,默認情況下爲回車鍵
android:imeOptions=“actionNone” //輸入框右側不帶任何提示
android:imeOptions=“actionGo” //右下角按鍵內容爲’開始’
android:imeOptions=“actionSearch” //右下角按鍵爲放大鏡圖片,搜索
android:imeOptions=“actionSend” //右下角按鍵內容爲’發送’
android:imeOptions=“actionNext” //右下角按鍵內容爲’下一步’ 或者下一項
android:imeOptions=“actionDone” //右下角按鍵內容爲’完成’
注意:如果設置了 鍵盤沒有變化 那麼需要單獨加一些其他的屬性 配合使用
xml中 屬性設置:
1 將singleLine設置爲true
2 將inputType設置爲text
java代碼設置
editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
本文來自 再見孫悟空_ 的CSDN 博客 ,全文地址請點擊:https://blog.csdn.net/shaoyezhangliwei/article/details/44805999?utm_source=copy