How to modify ImageButton image on press through XML?
I have an image button set up like so:
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/navup"
android:layout_weight="33"
android:layout_margin="5dip"
android:src="@drawable/up_button_icon"
android:background="@drawable/up_button" />
"@drawable/up_button_icon" is a png.
/res/drawable/up_button.xml:
<?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/up_button_press" />
<item
android:drawable="@drawable/up_button_norm" />
</selector>
The "press" states are png's that have a sunken look to them. Think of hitting a button on your tv's remote control.
The button is rendered correctly, however there is a problem when the button is pressed. The up_icon image stays stationary. For a better UI,开发者_C百科 the icon should shift down 2px so that it follows the "sunken" background.
Ideally, I would like to set this up through the XML layouts, but I am open to code solutions as well.
I think making a sunken version of the icon too and create another StateListDrawable
could be a solution.
精彩评论