我试图设置我的样式,使所有的按钮是一个特定的颜色组合,特别是蓝色与白色文本.这是我的主要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是白色的.在棒棒糖,按钮看起来完美.在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上正常工作的.
解决方法
使用AppCompat 22.1. (22.2.0也应该工作),我定义了一个这样的样式:
- <style name="MyApp.Button.Red" parent="Base.Widget.AppCompat.Button">
- <item name="colorButtonNormal">@color/primary</item>
- <item name="android:colorButtonNormal">@color/primary</item>
- <item name="android:textColor">@android:color/white</item>
- </style>
然后使用Android命名空间中的本机主题属性将主题应用于按钮,如Chris Banes的this令人惊叹的帖子中所述.
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/sign_up_button"
- android:theme="@style/MyApp.Button.Red" />