I am trying to very simply style a Button
. I just want it blue with with text when not pressed, and white with blue text when clicked.
I tried to do this with a style and a selector.
In my layout I have this Button
:
<Button
android:id="@+id/button1"
style="@style/MyButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/login" />
And in res/values/styles
I have this styles.xml
:
<style name="MyButton">
<item name="android:background">@drawable/btn_background</item>
<item name="android:textColor">@drawable/btn_textcolor</item>
</style>
And of course, the two selectors, in res/drawable
, btn_background.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="@color/white" />
<item android:color="@color/SapphireBlue" />
</selector>
and btn_textcolor.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="@color/SapphireBlue" />
<item android:color="@color/white" />
</selector>
The error I get now when I either run the app, or open the layout editor is:
<item> tag requires a 'drawable' attribute
I understand the message, but I don't have a drawable, is it is a simple, flat button.
How can I create such a simple button?
Update according to this post, it should work.