2015-04-21 3 views
0

Я пытался это IME_ACTIONsetOnEditorActionListener не работает на Android Lollipop

//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+.

+0

вы проверили в простой EditText вместо org.mapunity.widget.FloatingEditText? – BSavaliya

+0

да я сделал. Это не сработало! – sud007

ответ

4

У меня была та же проблема, что и вы. Итак, я провел некоторое тестирование с устройствами, которые у меня есть.

Результаты показывают, что устройства с API> 19 не реагируют на IME_ACTION

Итак, решение просто удалить if в вашем коде:

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

Большое вам спасибо !!! –

Смежные вопросы