【发布时间】:2017-03-12 10:34:03
【问题描述】:
我刚刚添加了一个自定义工具栏。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
请注意,我将背景设置为 colorPrimary。
在 style.xml 我有 2 种样式:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Yellow" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#ffff00</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#ffff00</item>
</style>
我的颜色.xml
<resources>
<color name="colorPrimary">#000</color>
<color name="colorPrimaryDark">#fff</color>
<color name="colorAccent">#000</color>
</resources>
我使用 setTheme 更改活动的颜色:
setTheme(colorId);
它可以工作,除了总是黑色的背景颜色,即使我将 setTheme 设置为黄色。
任何想法为什么?
【问题讨论】:
标签: android xml android-layout android-studio android-xml