I have been trying this 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.
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>
Please provide an input:
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.
The results indicate that devices with API > 19 don't respond to IME_ACTION
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;
}
});