Drawable resource not displaying with button
I'm trying to follow the tutorial located at http://www.dibbus.com/2011/02/gradient-buttons-for-android/, however I'm not getting the expected result. Everything compiles fine, however when I run it I get a button without any colors, gradients, or even borders (so actually all I see is just the button text). The button itself responds to events ok.
In order to be compatible with as many devices as possible I'm using android:minSdkVersion="3", could this be an issue?
This is part of my layout xml file:
<TableRow>
<Button
android:id="@+id/button_calculate"
android:background="@drawable/copy_btn"
android:layout_column="1"
android:layout_span="2"
android:padding="5dp" />
</TableRow>
This is copy_btn.xml, located inside drawables.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#70c656" />
<stroke
android:width="1dp"
android:color="#53933f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#70c656"
android:endColor="#53933f"
android:angle="270" />
开发者_如何学C<stroke
android:width="1dp"
android:color="#53933f" />
<corners
android:radius="4dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
Thanks
It works fine if u add android:layout_height="wrap_content" android:layout_width="wrap_content" to your button in Android Manifest. minSdkVersion has to do nothing with this as most of the times they are backward compatable.
What "(so actually all I see is just the button text)" means? How can u see a button text when u haven't used android:text attribute? Either there is another button in ur app or u r setting text from code. Do check this.
精彩评论