0

My android application uses custom images heavily, it will be a huge work to design "effect" images for each of them, e.g. clicking effect and others.

I'm looking for an easy solution. For example, when I click on a clickable component, it will look grey, and when my finger leaves, it will turn to the original color.

Is it possible?

Freewind
  • 193,756
  • 157
  • 432
  • 708

1 Answers1

3

Use xml selectors. That will do!

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@drawable/image_pressed" /> <!-- pressed/ clicked -->
    <item android:state_focused="true"
          android:drawable="@drawable/image_focused" /> <!-- focused -->
    <item android:state_hovered="true"
          android:drawable="@drawable/image_focused" /> <!-- hovered -->
    <item android:drawable="@drawable/image_normal" /> <!-- default / after release-->
</selector>

For more check here.

Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103