按钮样式在Android 5中工作,但在Android 4中不工作

按钮样式在Android 5中工作,但在Android 4中不工作,android,styles,android-5.1.1-lollipop,android-4.1-jelly-bean,Android,Styles,Android 5.1.1 Lollipop,Android 4.1 Jelly Bean,我有一个蓝色背景的按钮样式,在API22中效果很好,但是相同的按钮显示为深灰色,没有Android 4中应用的样式。这是我的风格: <style name="MyApp.Plain" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/background</item> <item name="android:b

我有一个蓝色背景的按钮样式,在API22中效果很好,但是相同的按钮显示为深灰色,没有Android 4中应用的样式。这是我的风格:

<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>

@可绘制/背景
@style/MyApp.Widget.Button
@可拉拔/btn_蓝色
真的
真的
大胆的
14便士
#fff
中心|垂直|中心|水平
我的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>

和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>

这种行为的原因是什么?我该如何解决

编辑:这不适用于支持v7:22.2.0,但适用于v7:21.0.3。除了依赖项之外,我没有做任何更改,而是将AppCompatActivity更改为ActionBarActivity


这可能是一个Android错误

我见过一些布局,其中属性应用了两次,有和没有Android前缀。你能试试这个吗

<style name="MyApp.Widget.Button" parent="@android:style/Widget.Button">
      <item name="android:background">@drawable/btn_blue</item>
      <item name="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>

@可拉拔/btn_蓝色
@可拉拔/btn_蓝色
真的
真的
大胆的
14便士
#fff
中心|垂直|中心|水平
我目前正试图找到我以前在哪里看到的,以及它为什么起作用。如果有,请告诉我。

尝试使用AppCompat:

    <style name="MyApp.Widget.Button" parent="Base.TextAppearance.AppCompat.Button">
     <item name="android:background">@drawable/btn_blue</item>
      ...
    </style>

@可拉拔/btn_蓝色
...

尝试
按钮样式
而不是
安卓:按钮样式
,因为这是棒棒糖前的AppCompat属性,所以它应该没有安卓前缀。

@MichałKisiel回答正确“尝试使用
buttonStyle
而不是
android:buttonStyle
,因为这是棒棒糖前的AppCompat属性,所以它应该没有android前缀。” 我只想添加一个,例如,如果您以编程方式创建一个视图,那么您应该将android:buttonStyle和buttonStyle也放进去,示例:

    <item name="android:buttonStyle">@style/OrangeButton</item>
    <item name="buttonStyle">@style/OrangeButton</item>
@style/OrangeButton
@样式/橙色按钮

显示可绘制的/btn_蓝色内容是否有可能为API版本设置单独的文件夹,并且此样式仅在其中一个文件夹中?@mcAdam331:没有,我只有一个样式文件。所有其他属性都有效吗?是否可以单击?文本样式是否也在4中加粗?是否仅在背景上失败?是否可以单击,但出于某些原因n文本都是大写的,不是粗体的,而是相同的颜色。谢谢,我试过了,但不幸的是API 10上的按钮仍然是灰色背景。@barq我想这是值得一试的。你能像Lucas问的那样发布btn_蓝色的内容吗?那么问题可能就在那里。@barq我找到了我想的,它与支持库有关:我要离开我的a现在请回答,以防我可以编辑它并在以后帮助你。是的,我也在看这个问题。不幸的是,这不起作用,至少它本身不起作用。谢谢,但这也不起作用,不幸的是。你是否将样式设置为按钮?不,这是应用程序的常规按钮样式,因此应该没有必要。它可以在不做任何操作的情况下工作在安卓5中。这应该被接受为答案,修复了我的问题!谢谢。