[英]detect keyboard search button
I change android soft keyboard to show search icon rather than Enter icon.我更改了 android 软键盘以显示搜索图标而不是 Enter 图标。 My question is: how i can detect that user click on that search button?
我的问题是:我如何检测该用户点击该搜索按钮?
In the edittext you might have used your input method options to search. 在edittext中,您可能已使用输入法选项进行搜索。
<EditText
android:imeOptions="actionSearch"
android:inputType="text"/>
Now use the Editor listener on the EditText to handle the search event as shown below: 现在使用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;
}
});
You can use OnQuerySubmit
listener to get keyboard Search button click event. 您可以使用
OnQuerySubmit
侦听器来获取键盘搜索按钮单击事件。
Here's how, 这是如何做,
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.