【发布时间】:2016-03-23 14:37:54
【问题描述】:
在我的应用程序中,我有 3 个activities,每个activity 具有相同的Toolbar,并包含自定义样式(背景颜色为蓝色)。
从Activity-A 用户可以更改toolbar 的背景颜色(从蓝色变为红色)。它在Activity-A 的toolbar 上正常工作,但是当我从Activity-A 转到Activity-B 时,toolbar 的颜色是前一个(背景颜色是蓝色而不是红色)。
我的toolbar 是:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:theme="@style/myToolbarTheme"
android:layout_width="match_parent"
android:layout_height="48dp"
android:padding="0dp">
</android.support.v7.widget.Toolbar>
自定义样式是:
<style name="myToolbarTheme">
<item name="android:background">@color/themeBlue</item>
</style>
要更改正在使用的工具栏的背景颜色,
toolbar.setBackgroundColor(getResources().getColor(R.color.themeRed));
所以我的问题是,如何为每个活动的工具栏设置相同的颜色?请给我建议。
谢谢
【问题讨论】:
-
定义通用工具栏颜色的样式
-
你能解释一下吗?