Android的:如何使键盘的回车键说"搜索"而处理其点击? [英] Android: how to make keyboard enter button say "Search" and handle its click?
问题描述
我不明白这一点。有些应用程序具有的EditText(文本框),当你触摸它,它带来了屏幕上的键盘,键盘上有一个搜索按钮,而不是一个回车键。
I can't figure this out. Some apps have a EditText (textbox) which, when you touch it and it brings up the on-screen keyboard, the keyboard has a "Search" button instead of an enter key.
我想实现这一点。我如何可以实现搜索按钮和检测的搜索按钮的preSS?
I want to implement this. How can I implement that Search button and detect press of the Search button?
修改:发现如何实现的搜索按钮;在XML中,安卓imeOptions =actionSearch
或在Java中, EditTextSample.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
。但我怎么处理用户pressing的搜索按钮?它有事可做与安卓?imeActionId
Edit: found how to implement the Search button; in XML, android:imeOptions="actionSearch"
or in Java, EditTextSample.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
. But how do I handle the user pressing that Search button? Does it have something to do with android:imeActionId
?
推荐答案
在布局设置输入法选项进行搜索。
In the layout set your input method options to search.
<EditText android:imeOptions="actionSearch"
android:inputType="text"/>
在Java中添加编辑器动作监听器。
In the java add the editor action listener.
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;
}
});
这篇关于Android的:如何使键盘的回车键说&QUOT;搜索&QUOT;而处理其点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!