Tag <item> wymaga atrybutu „drawable”
Staram się po prostu w styluButton
. Chcę tylko, aby był niebieski z tekstem, gdy nie został naciśnięty, i biały z niebieskim tekstem po kliknięciu.
Próbowałem to zrobić za pomocą stylu i selektora.
W moim układzie mam toButton
:
<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" />
I wres/values/styles
Mam tostyles.xml
:
<style name="MyButton">
<item name="android:background">@drawable/btn_background</item>
<item name="android:textColor">@drawable/btn_textcolor</item>
</style>
I oczywiście dwa selektory, wres/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>
ibtn_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>
Błąd, który otrzymuję teraz, gdy uruchamiam aplikację lub otwieram edytor układu, to:
Tag <item> wymaga atrybutu „drawable”
Rozumiem wiadomość, ale nie wiemmieć drawable, to prosty, płaski przycisk.
Jak mogę stworzyć taki prosty przycisk?
Aktualizacja wedługten post, powinno działać.