Как изменить цвет фона ActionBar в новых MaterialComponents - PullRequest
0 голосов
/ 28 февраля 2019

Я использую новые 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

Я знаю о этот вопрос , но он устарел и не использует MaterialComponents

Я не хочу добавлять Панель инструментов на каждый экран просто для изменения цвета фона.

1 Ответ

0 голосов
/ 28 февраля 2019

Вам нужно использовать 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>
...