I am trying to make a custom button, having two 9patch files, one for normal state and one for status.
First I tried with a simple 9patch background and the result is fine:
<Button android:id="@+id/btnTest"
android:layout_height="80dip"
android:layout_width="135dip"
android:text="Test"
android:drawableTop="@drawable/imgsomeimage"
android:background="@drawable/main_button_background">
</Button>
I get a button with a image and a text bellow it. Everything with the main_button_background underneath
I create a new xml file (main_menu_button.xml) with the following content
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/main_button_background" />
<item
android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/main_button_background" />
<!-- Focused states -->
<item
android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/main_button_background_pressed" />
<item
android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/main_button_background_pressed" />
<!-- Pressed -->
<item
android:state_pressed="true"
android:drawable="@drawable/main_button_background_pressed" />
</selector>
The button becomes:
<Button android:id="@+id/btnTest"
android:layout_height="80dip"
android:layout_width="135dip"
android:text="Test"
android:drawableTop="@drawable/imgsomeimage"
android:background="@drawable/main_menu_button">
Now the text isn't displayed, only the background and the imgsomeimage. What am I doing wrong ?