我正尝试做这种编程方式更改的工具栏背景颜色:更改工具栏的背景色编程不改变工具栏标题背景颜色
getSupportActionBar().setBackgroundDrawable(newColorDrawable(getResources().getColor(R.color.test_color_blue)));
这是结果:
前:
后:
一些如何工具栏标题仍然具有与以前相同的背景颜色。
这里是我的工具栏的xml:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/Theme.Toolbar">
这里是主题:
<style name="Theme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:maxHeight">@dimen/abc_action_bar_default_height_material</item>
<item name="android:background">@color/primary</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@android:color/white</item>
<item name="titleTextAppearance">@style/Theme.Toolbar.Title</item>
</style>
您是否在styles.xml中为操作栏应用了任何自定义样式,可能其中一些是冲突的。 – Harry 2015-04-06 09:10:54
张贴您的布局xml请 – 2015-04-06 14:27:36
@DavidJhons我已经发布了有关问题的新细节 – EkKoZ 2015-04-06 15:11:47