setOnEditorActionListener不适用于Android Lollipop

时间:2015-04-21 06:56:05

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

我一直在尝试这个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 +。

1 个答案:

答案 0 :(得分:5)

我遇到了同样的问题。所以,我已经使用我拥有的设备进行了一些测试。

结果表明具有API的设备> 19不要回应IME_ACTION

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

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