我将尝试设置我的样式,使所有的按钮都具有特定的颜色组合,具体而言是蓝底白字。这是我的主要样式文件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上正常工作的原因。