【发布时间】:2020-06-18 18:53:35
【问题描述】:
我正在尝试通过这样做以编程方式更改工具栏背景颜色:
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中为actionbar应用了任何自定义样式,可能其中一些是冲突的。
-
请发布您的布局 xml
-
@DavidJhons 我已经发布了有关问题的新细节
标签: android android-actionbar android-toolbar