There is an EditText , it has a drawableRight set, but when you drawableRight on it, there is no action display, i.e. it is not clear whether I clicked or not.

How can I set the effect of pressing?

Usually installed with:

 android:background="?attr/selectableItemBackgroundBorderless" 

.

 <EditText xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/search" android:layout_width="248dp" android:layout_height="wrap_content" android:layout_gravity="center" android:drawableEnd="@drawable/ic_search_black_24dp" android:drawableRight="@drawable/ic_search_black_24dp" android:hint="@string/search_query_hint" /> 

    1 answer 1

    In this case, you are not working with the background of the entire widget, but with a separate image on the widget, therefore, it is wrong to assign a click to the background.

    In order to have the effect of pressing the image, you need, first, to prepare images for each state. For example, the view of the pressed state ic_search_black_pressed.png and default (normal) ic_search_black.png .
    Then you need to write a selector that will respond to each state, let's call it search_black_selector.xml (located in the res / drawable / folder):

     <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/ic_search_black_pressed.png" /> <!-- изображение для нажатого состояния --> <item android:drawable="@drawable/ic_search_black" /> <!-- изображение нормального состояния --> </selector> 

    Now we connect this selector to EditText instead of the static image:

     <EditText xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/search" android:layout_width="248dp" android:layout_height="wrap_content" android:drawableRight="@drawable/search_black_selector" /> 

    It is also possible to react to other states of the widgets and their combinations - the official guide on the issue