軟鍵盤的字體改變 搜索

默認情況,鍵盤右下角爲Enter鍵。EditText提供了android:imeOptions屬性,控制該文字顯示。
1、android:imeOptions="actionSearch" 文字爲搜索
2、android:imeOptions="actionGo" 文字爲開始
3、android:imeOptions="actionSend" 文字爲發送
4、android:imeOptions="actionDone" 文字爲Enter鍵
注意:android:imeOptions起作用,必須加上android:inputType屬性或者android:singleLine="true"屬性。

監聽用戶按下該鍵事件,實現OnEditorActionListener接口,重寫onEditorAction()發法,其中第二個參數爲軟鍵盤action對應的Id,都在EditorInfo類裏,比如actionGo對應EditorInfo.IME_ACTION_GO,之後return true,給editText添加監聽器即可。


@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND//發送
|| actionId == EditorInfo.IME_ACTION_NEXT//下一個
|| actionId == EditorInfo.IME_ACTION_SEARCH//搜索
|| actionId == EditorInfo.IME_ACTION_SEND
|| (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
str = etSearch.getText().toString();
iSearchHeader.searchHeader();

return true;
}
return false;
}

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