Reputation: 357
I need to set a background color and an image over that background, how can i do it? Is necesary the image to have transparency? I need to control states too: pressed, focused.
Any help will be grateful
Upvotes: 1
Views: 9699
Reputation: 5551
Create an ImageView (Use a transparent .PNG for your src image):
res/layout/yourlayout.xml
<ImageView
android:layout_width=:"wrap_content"
android:layout_height=:"wrap_content"
android:background="@drawable/colorstates"
android:src="@drawable/image" />
res/drawable/colorstates.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/regular"
android:state_checked="true"
android:state_pressed="true" />
<item
android:drawable="@drawable/pressed"
android:state_pressed="true" />
<item
android:drawable="@drawable/pressed"
android:state_checked="true" />
<item
android:drawable="@drawable/regular" />
</selector>
Upvotes: 6