Enable "Search" android keyboard

1

Again here! In some applications we can notice a button on the keyboard with the drawing of a magnifying glass .. this keyboard, or button, if it becomes necessary to be enabled in the application? I looked for several ways to add the same and create a search event for him but I did not succeed, has anyone ever had a similar situation? Thanks!

    
asked by anonymous 06.03.2015 / 19:29

1 answer

1

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

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

To handle the click on this button, you can use the listener 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;
    }
});
    
06.03.2015 / 19:44