【问题标题】:setOnEditorActionListener is not working for Android LollipopsetOnEditorActionListener 不适用于 Android Lollipop
【发布时间】:2015-06-28 04:32:34
【问题描述】:

我一直在尝试这个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;
        }
    });

但似乎它在 Lollipop 设备上根本不起作用。

这是 XML 代码 - 我完全确定我做对了。

 <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>

请提供输入:

知道有很多类似的问题,但我的问题是关于 Lollipop,即 Android 5.0+。

【问题讨论】:

  • 您是否签入了简单的 EditText 而不是 org.mapunity.widget.FloatingEditText ?
  • 是的,我做到了。没用!

标签: android android-5.0-lollipop keyboard-events


【解决方案1】:

我遇到了和你一样的问题。所以,我用我拥有的设备做了一些测试。

结果表明 API > 19 的设备不响应​​ IME_ACTION

因此,解决方案就是删除代码中的if 语句:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多