【发布时间】:2015-09-01 18:33:46
【问题描述】:
我正在尝试设置我的样式以使所有按钮具有特定的颜色组合,特别是蓝色和白色文本。这是我的主要styles.xml:
<resources>
<style name="CustomTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
<!-- various items -->
<item name="android:buttonStyle">@style/ButtonStyle</item>
</style>
<!-- a couple of other styles -->
<style name="ButtonStyle" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:textColor">@color/primaryTextContrast</item>
<item name="android:background">@color/primary</item>
</style>
</resources>
在清单中:
<application
android:name=".CustomApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/application_name"
android:theme="@style/CustomTheme">
color/primary 是深蓝色,color/primaryTextContrast 是白色。在 Lollipop 上,按钮看起来很完美。在 4.1 设备上,它是带有黑色文本的浅灰色。我找到的用于执行此操作的每个资源看起来都与我正在做的完全一样,所以我不知道我在这里缺少什么。
我在控制基本样式定义中的文本大小时也遇到了类似的问题。
更新:这里是颜色。
<resources>
<color name="primary">#3F51B5</color>
<color name="dark">#303F9F</color>
<color name="accent">#FFCA28</color>
<color name="background">@android:color/white</color>
<!-- Color for text displayed on top of the primary or dark color -->
<color name="primaryTextContrast">@android:color/white</color>
<!-- Color for text displayed on the background color (which I think will always be white) -->
<color name="basicText">@color/primary</color>
<!-- Color for text displayed on the accent color -->
<color name="accentText">#303F9F</color>
</resources>
这里是 v19/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="FullscreenTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
这里是 v21:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="CustomTheme">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
</resources>
我认为这些都不是让它在 5.1 上正常工作的原因。
【问题讨论】:
-
您的代码在我的galaxy s3 mini (Android 4.1) 上完美运行,您确定您没有两个版本的styles.xml,而带有此代码的版本是> v16?
-
我有两个版本,但这是 main/res/values 中的一个。
-
@Jones 我添加了其他样式文件。