[英]detect keyboard search button
我更改了 android 軟鍵盤以顯示搜索圖標而不是 Enter 圖標。 我的問題是:我如何檢測該用戶點擊該搜索按鈕?
在edittext中,您可能已使用輸入法選項進行搜索。
<EditText
android:imeOptions="actionSearch"
android:inputType="text"/>
現在使用EditText上的Editor監聽器來處理搜索事件,如下所示:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
// Your piece of code on keyboard search click
return true;
}
return false;
}
});
您可以使用OnQuerySubmit
偵聽器來獲取鍵盤搜索按鈕單擊事件。
這是如何做,
searchView.setOnQueryTextListener(queryTextListener);
SearchView.OnQueryTextListener queryTextListener
= new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
showLog("searchClickListener onQueryTextSubmit");
getPhotos(searchView.getQuery().toString());
return true;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.