Android highlights ImageButton onclick

Is there a way to highlight ImageButtonwhen clicked?

+3
source share
2 answers

You can determine the ability to draw through XML and use the selector as shown below to use different (i.e., selected) images for different button states:

i.e. Res / draw / button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/bg_catlocfilter" android:state_pressed="false" />
    <item android:drawable="@drawable/bg_catlocfilter_dark" android:state_pressed="true" />
    <item android:drawable="@drawable/bg_catlocfilter" android:state_focused="false" />
    <item android:drawable="@drawable/bg_catlocfilter_dark" android:state_focused="true" />

</selector>

Use this resource, then to represent the ImageButton.

+13
source

Refer this link. I ran into the same problem and solved now. Hope this helps :-)

0
source

Source: https://habr.com/ru/post/1751859/


All Articles