我搞不懂这个。有些应用程序在EditText (textbox)的帮助下,当你触摸它并打开屏幕键盘时,键盘上有一个“搜索”按钮,而不是一个enter键。
我想实现这一点。如何实现该搜索按钮并检测按下的搜索按钮?
编辑:找到了如何实现搜索按钮;在XML、android:imeOptions="actionSearch"
或EditTextSample.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
中。但是如何处理用户按下搜索按钮呢?这和android:imeActionId
有关吗?
发布于 2010-07-08 07:44:26
在布局中,将输入方法选项设置为搜索。
<EditText
android:imeOptions="actionSearch"
android:inputType="text" />
在java中添加编辑器操作侦听器。
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
发布于 2017-03-16 00:50:23
当用户单击搜索时隐藏键盘。除了Robby Pond的答案
private void performSearch() {
editText.clearFocus();
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(editText.getWindowToken(), 0);
//...perform search
}
发布于 2016-11-29 05:15:40
在xml
文件中,放置imeOptions="actionSearch"
和inputType="text"
、maxLines="1"
<EditText
android:id="@+id/search_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/search"
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1" />
https://stackoverflow.com/questions/3205339
复制