【发布时间】:2015-11-04 04:52:44
【问题描述】:
我有一个蓝色背景的按钮样式,在 API 22 中可以正常工作,但在 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>
我的 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 错误。
【问题讨论】:
-
显示drawable/btn_blue的内容
-
您是否有可能为 API 版本提供单独的文件夹,而这种样式仅在其中一个中?
-
@mcAdam331:不,我只有一个样式文件。
-
所有其他属性都有效吗?是否可以点击? 4中的文字样式也是粗体吗?是否仅在后台失败?
-
它是可点击的,但由于某种原因,文本全部大写,不是粗体,而是相同的颜色。
标签: android styles android-5.1.1-lollipop android-4.1-jelly-bean