Long time stackoverflow reader, first time with a question. The problem I am having seems silly, but I can't find any information that explains it.
I am new to Android programming and am working on a project with custom button backgrounds. I am using state list drawables for the different buttons that look like this:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/button_pressed_background" android:gravity="center"/>
android:state_pressed="true"
</item>
<item>
<bitmap android:src="@drawable/button_focused_background" android:gravity="center"/>
android:state_focused="true"
</item>
<item>
<bitmap android:src="@drawable/button_standard_background" android:gravity="center"/>
android:state_pressed="false"
android:state_focused="false"
</item>
</selector>
In the xml where the buttons are declared, I simply add the line android:background="@drawable/button_drawable"
where button_drawable.xml is the state list drawable.
Seems simple enough, but in all cases, the buttons display with the background listed in the first <item>
section of the state list drawable, no matter their state. In fact, in the example above, I could change the first <item>
section to include android:state_pressed="false"
instead, and the button_pressed_background
still displays! It is as if all button states are true and false simultaneously.
I am developing using emulators, but see this behavior both with the AVD emulator and with Android x86 running on Oracle VirtualBox. Any idea why this would occur?