我正在使用新的 MaterialComponents我的应用主题是:
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
<item name="colorAccent">@color/secondaryColor</item>
</style>
如何改变ActionBar的背景色
我知道 this question但它已经过时并且不使用 MaterialComponents
我不想为每个屏幕添加工具栏只是为了更改背景颜色。
最佳答案
您需要根据背景颜色使用 ThemeOverlay.MaterialComponents.ActionBar
或 ThemeOverlay.MaterialComponents.Dark.ActionBar
。
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
<item name="colorAccent">@color/secondaryColor</item>
<item name="actionBarTheme">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/ThemeOverlay.MaterialComponents.ActionBar">
<item name="android:background">#fff</item>
</style>
关于android - 如何在新的 MaterialComponents 中更改 ActionBar 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54934013/