setOnEditorActionListener不工作为Android棒棒糖 [英] setOnEditorActionListener is not working for Android Lollipop

查看:1952
本文介绍了setOnEditorActionListener不工作为Android棒棒糖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试这种 IME_ACTION

 //Listening to the keyboard action
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == R.id.ime_search || actionId == EditorInfo.IME_ACTION_SEARCH) {

                performSearch();
                return true;
            }
            return false;
        }
    });

但好像它根本不棒棒糖上的设备上工作。

but seems like it doesn't at all work on Lollipop devices.

下面是XML code - 我完全确信,我这样做的权利。

Here is the XML code - I am completely sure that I am doing this right.

 <org.mapunity.widget.FloatingEditText
        android:id="@+id/fragment_search_edit_text"
        android:hint="Enter a Text to Search"
        android:layout_marginTop="@dimen/spacing_small"
        android:layout_marginBottom="@dimen/spacing_small"
        android:singleLine="true"
        app:floating_edit_text_highlighted_color="@color/color_primary"
        android:layout_marginLeft="@dimen/spacing_normal"
        android:imeActionLabel="@string/action_search"
        android:imeOptions="actionSearch"
        android:imeActionId="@+id/ime_search"
        android:inputType="text"
        android:layout_marginRight="@dimen/spacing_normal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <requestFocus></requestFocus>
        </org.mapunity.widget.FloatingEditText>

请提供一个输入:

我知道也有很多类似的问题,但我的是专门关于棒棒堂,即是Android 5.0 +

I know there are a lot of similar questions but mine is specifically about Lollipop, i.e. Android 5.0+.

推荐答案

我有,你没有同样的问题。所以,我做了一些测试与我的设备。

I had the same problem that you did. So, I've done some testing with the devices that I have.

研究结果表明,与API设备> 19不以IME_ACTION回应

The results indicate that devices with API > 19 don't respond to IME_ACTION

因此​​,该解决方案只是删除如果语句在code:

So, the solution is just to remove the if statement in your code:

mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        performSearch();
        return true;
    }
});

这篇关于setOnEditorActionListener不工作为Android棒棒糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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