Can't I get "Search" into the keyboard enter button on Android?

Asked 2 years ago, Updated 2 years ago, 123 views

In some apps, when you click EditText, the keyboard comes up and there is a search button instead of the Enter button. I also want to implement it like this, but how can I implement the search button and know how it is pressed?

android android-softkeyboard

2022-09-22 22:21

1 Answers

Go to layout xml

<EditText android:imeOptions="actionSearch" 
    android:inputType="text"/>

Please do this on EditText.

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            performSearch();
            return true;
        }
        return false;
    }
});

You can process the search button in Java code like this.


2022-09-22 22:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.