Enable android keyboard "Search" key

Asked

Viewed 686 times

1

here again! In some apps we can notice a button on the keyboard with the drawing of a magnifying glass.. that keyboard, or button, if it is necessary to be enabled in the application? I tried several ways to add the same and create a research event for it but I did not succeed, has anyone ever gone through a similar situation? Thank you!

1 answer

1

This button on the keyboard is called IME, and you can configure (in your case) through the attribute android:imeOptions="actionSearch":

<EditText 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:imeOptions="actionSearch" 
    android:inputType="text"/>

To treat the click on this button, you can use the System OnEditorActionListener:

seuEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            //suas implementações
            return true;
        }
        return false;
    }
});
  • 1

    Declaring a new Textview even using Edittext cannot give a conflict?

  • @diegofigueiredo não! In the documentation itself (here http://developer.android.com/reference/android/widget/EditText.html) is like this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.