简体   繁体   English

在键盘上实现搜索按钮

[英]Implementing Search Button on my Keyboard

I'm trying to implement a search button in place of the regular enter button on my inbuilt android keyboard. 我正在尝试在内置的Android键盘上实现搜索按钮来代替常规的Enter按钮。 I tried doing: 我试着做:

resultView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
System.out.println("You searched for this!");
return true;
}
return false;
}

But the regular 'enter' button is still appearing. 但是常规的“输入”按钮仍会出现。 I do not want to use XML and i'm creating my UI completely on JAVA. 我不想使用XML,而是完全在JAVA上创建UI。 What should i do? 我该怎么办? Help would be appreciated. 帮助将不胜感激。 Thanks! 谢谢!

    EditText view = new EditText(this);
    view.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    view.setSingleLine(true);

And you are good to go, you set SingleLine attribute to change the new line button "default behavior in multi-line editext" to search button . 一切顺利,您将SingleLine属性设置为将新行按钮“多行editext中的默认行为”更改为搜索按钮。

Sounds like you need to set the imeOptions programmatically. 听起来您需要以编程方式设置imeOptions。 Try something like this: 尝试这样的事情:

editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

You might have to play around with the available options to get exactly what you want. 您可能需要尝试使用可用的选项才能确切获得所需的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM