雖然通常輸入法軟鍵盤右下角會是回車按鍵
但我們經常會看到點擊不同的編輯框,輸入法軟鍵盤右下角會有不同的圖標
點擊瀏覽器網址欄的時候,輸入法軟鍵盤右下角會變成“GO”或“前往”
而我們點擊Google搜索框,輸入法軟鍵盤右下角會變成 放大鏡 或者“搜索”
而決定這個圖標的變換的參數就是EditText中的 android:imeOptions
android:imeOptions的值有actionGo、 actionSend 、actionSearch、actionDone等,這些意思都很明顯
<EditText
android:id="@+id/setting_search_edit"
android:layout_width="200dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:background="@null"
android:singleLine="true"
android:imeOptions="actionSearch"
android:textSize="11sp" />
在代碼中通過editText.setOnEditorActionListener方法添加相應的監聽,因為有些action是需要在代碼中添加具體的相關操作的
mSearchEdit.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView text, int actionId, KeyEvent event) {
mSearch = true;
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
nameList.clear();
idList.clear();
headpicList.clear();
for (int i = 0; i < blackListName.size(); i++) {
if (blackListName.get(i).contains(mSearchEdit.getText())) {
nameList.add(blackListName.get(i));
idList.add(blackListId.get(i));
headpicList.add(blackListHeadpic.get(i));
}
}
mAdapter = new BlackListAdapter(FilterlistActivity.this, mChecked, idList,
nameList, headpicList, photoLoader);
mListView.setAdapter(mAdapter);
}
return false;
}
});
設置無效時需要設置一下一項
1 將singleLine設置為true
2 將inputType設置為text
