3

I am following material design tutorials as well as icons to develop an application, but I found an app which changes icons color on click. I want to do the same. How I can build such things? Please help me to out of this problem, also on button click snackbar's color get changed.

enter image description here

Thank you

AkhilGite
  • 400
  • 4
  • 17

2 Answers2

0

You can make that with selector.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="resource when button is pressed"/>
    <item android:state_pressed="false" android:drawable="resource when button is not pressed"/>
</selector>

if you want apply that selector on your button, follow this step.

  1. make resource(.xml) file.
  2. input xml code(selector) inside of resource tag.
  3. set background on your button like this: button.setbackground(@drawable/xml);
Kae10
  • 619
  • 2
  • 6
  • 17
0

try this selector to change images for selection or your image button

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:state_pressed = "true"
    android:drawable="@drawable/your_icon_pressed"/>
<item
    android:drawable="@drawable/your_icon"/>
</selector>
Saif
  • 723
  • 6
  • 21