Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button style working in Android 5 but not Android 4

I have a button style with a blue background that works fine in API 22, but the same button appears in dark grey without the applied style in Android 4. This is my style:

<style name="MyApp.Plain" parent="Theme.AppCompat.NoActionBar">
      <item name="android:windowBackground">@drawable/background</item>
      <item name="android:buttonStyle">@style/MyApp.Widget.Button</item>
</style>


  <style name="MyApp.Widget.Button" parent="@android:style/Widget.Button">
      <item name="android:background">@drawable/btn_blue</item>
      <item name="android:focusable">true</item>
      <item name="android:clickable">true</item>
      <item name="android:textStyle">bold</item>
      <item name="android:textSize">14sp</item>
      <item name="android:textColor">#fff</item>
      <item name="android:gravity">center_vertical|center_horizontal</item>
   </style>

My btn_blue.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/btn_disabled" android:state_enabled="false"/>
    <item android:drawable="@drawable/btn_pressed" android:state_enabled="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/btn_normal_blue" android:state_enabled="true"/>

</selector>

and btn_normal_blue.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient
        android:angle="90"
        android:endColor="#368ac6"
        android:startColor="#0e58a4" />

    <corners android:radius="20dp" />

</shape>

What could be the reason for this behavior and how can I fix this?

EDIT: This does not work with support v7:22.2.0, but does work with v7:21.0.3. I didn't change anything besides the dependency and changed AppCompatActivity to ActionBarActivity.

Possibly this is an Android bug.

like image 459
barq Avatar asked Aug 11 '15 19:08

barq


1 Answers

Try buttonStyle instead of android:buttonStyle, since this is AppCompat attribute pre Lollipop, so it should be without android prefix.

like image 137
Michał Kisiel Avatar answered Oct 19 '22 04:10

Michał Kisiel