修改軟鍵盤右下角的確定樣式

在對Android的EditText控件進行設置時,經常會限定一下輸入法的屬性,設置右下角為完成或者搜索等,我們使用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 發(fā)送,對應常量EditorInfo.IME_ACTION_SEND
6.actionNext 下一個,對應常量EditorInfo.IME_ACTION_NEXT
7.actionDone 完成,對應常量EditorInfo.IME_ACTION_DONE
使用起來很簡單,給你的EditText控件設置其中一個屬性就行了。比如:
我想要讓軟件盤右下角變成搜索的字樣或者是圖標:

<EditText
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:singleLine="true"
    android:imeOptions="actionSearch "/>
//在代碼中去設置它的OnEditorActionListener監(jiān)聽方法。
//用來判斷事件類型是不是EditorInfo.IME_ACTION_SEARCH,然后寫下對應的邏輯既可。

這樣既可。
在一開始使用的時候遇到一個問題,就是明明設置了其選項居然沒有用。百度之后發(fā)現(xiàn)原來要給他在設置一下singleLine屬性才行。單獨使用無效。切記。
順便在說一下android的輸入類型:
根據(jù)要輸入的內容展現(xiàn)相應的軟件盤,可通過修改android:inputType 來實現(xiàn)。
這是一些常用的輸入類型。

android:inputType="none" //輸入普通字符  
android:inputType="text" //輸入普通字符  
android:inputType="textCapCharacters" //輸入普通字符  
android:inputType="textCapWords"http://單詞首字母大小  
android:inputType="textCapSentences"http://僅第一個字母大小  
android:inputType="textAutoCorrect"http://前兩個自動完成  
android:inputType="textAutoComplete"http://前兩個自動完成  
android:inputType="textMultiLine"http://多行輸入  
android:inputType="textImeMultiLine"http://輸入法多行(不一定支持)  
android:inputType="textNoSuggestions"http://不提示  
android:inputType="textUri"http://URI格式  
android:inputType="textEmailAddress"http://電子郵件地址格式  
android:inputType="textEmailSubject"http://郵件主題格式  
android:inputType="textShortMessage"http://短消息格式  
android:inputType="textLongMessage"http://長消息格式  
android:inputType="textPersonName"http://人名格式  
android:inputType="textPostalAddress"http://郵政格式  
android:inputType="textPassword"http://密碼格式  
android:inputType="textVisiblePassword"http://密碼可見格式  
android:inputType="textWebEditText"http://作為網頁表單的文本格式  
android:inputType="textFilter"http://文本篩選格式  
android:inputType="textPhonetic"http://拼音輸入格式  
android:inputType="number"http://數(shù)字格式  
android:inputType="numberSigned"http://有符號數(shù)字格式  
android:inputType="numberDecimal"http://可以帶小數(shù)點的浮點格式  
android:inputType="phone"http://撥號鍵盤  
android:inputType="datetime"  
android:inputType="date"http://日期鍵盤  
android:inputType="time"http://時間鍵盤  
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容