I created custom images with 9 patches for the background of my button. The buttons are in the drawable-hdpi and drawable-mdpi folders. I created a custom selector file for button states.
Login_button.xml selector file:
<?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/login_button_down" />
<item android:state_focused="true" android:drawable="@drawable/login_button_down" />
<item android:drawable="@drawable/login_button" />
</selector>
Then I created my own styles.xml file for the button style:
<style name="login_button_style" parent="@android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FF000000</item>
<item name="android:shadowColor">#FFFFFFFF</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">0.2</item>
<item name="android:textSize">13dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">@drawable/login_button</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
Then applied this style to my theme file in topic.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="@android:style/Theme.NoTitleBar" >
<item name="android:editTextStyle">@style/login_edittext_style</item>
<item name="android:buttonStyle">@style/login_button_style</item>
<item name="android:textViewStyle">@style/login_textview_style</item>
</style>
</resources>
And finally, the button itself is added to the layout file:
<Button
android:text="@string/login_text"
android:id="@+id/buttonSignIn"
android:layout_width="130dp"
android:layout_height="wrap_content">
</Button>
But if I press the button, then the background image will not be changed. The code is fine and everything compiles nicely. I know that I have the same image for two different states, but it does not work even for one state in the emulator. Can someone point me where the problem is?
EDIT:
, , XML selector. , ...