Android:如何让键盘输入按钮说“搜索"并处理它的点击? [英] Android: how to make keyboard enter button say "Search" and handle its click?

查看:19
本文介绍了Android:如何让键盘输入按钮说“搜索"并处理它的点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不通.一些应用程序有一个 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.

我想实现这一点.如何实现该搜索"按钮并检测搜索"按钮的按下情况?

I want to implement this. How can I implement that Search button and detect press of the Search button?

编辑:找到了如何实现搜索按钮;在 XML 中,android:imeOptions="actionSearch" 或在 Java 中,EditTextSample.setImeOptions(EditorInfo.IME_ACTION_SEARCH);.但是我如何处理用户按下该搜索"按钮?和android: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:如何让键盘输入按钮说“搜索"并处理它的点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆