So I applied a custom style to my buttons, it works ok with API level 22, but when I test it with API level 16 all my custom styles are gone. What's happening here?. I am an android beginner so probably it's a common behavior but I couldn't find any answer.
Styles are split into 4 xml's representing button states: Pressed, focused, disabled and enabled. I grouped them in 1 xml called button.xml and applied it in styles.xml
button_pressed.xml (focused, disabled and enabled are similar)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://ift.tt/nIICcg"
android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="#004B8D"
android:startColor="#0865B7" />
<size
android:height="65dp"
android:width="65dp"/>
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
<corners android:radius="3dp" />
</shape>
button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg">
<item
android:state_enabled="false"
android:drawable="@drawable/button_disabled" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/button_pressed" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/button_focused" />
<item
android:state_enabled="true"
android:drawable="@drawable/button_enabled" />
</selector>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name ="android:buttonStyle">@style/button</item>
</style>
<style name="button" parent="@android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFFFF</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">-1</item>
<item name="android:shadowRadius">0.4</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">@drawable/button</item>
<item name="android:focusable">false</item>
<item name="android:clickable">true</item>
<item name="android:fontFamily">sans-serif-condensed</item>
</style>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire