AndroidDev
AndroidDev

Reputation: 16405

Android ImageButton background change when clicked

I have an image button that has a transparent background and a image as a foreground. What i want to do is to make the button flash when i press the button. Now i don't want to define two different images for the up and down state, is there any why i can define a selector color for the background and foreground and the background of the button ?

Kind Regards,

Upvotes: 0

Views: 664

Answers (1)

Vishesh Chandra
Vishesh Chandra

Reputation: 7071

You can use this code for background selection of button for diff-2 state of button, save this file in drawable folder and set button background. Hope it will useful to you...:)

<?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/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
      android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>

Upvotes: 1

Related Questions