4

I am in the process of migrating my app theme to a Material Design theme and I am having problems with certain situations where I need a transparent status bar (for example when using a CollapsingToolbarLayout, when expanded the toolbar should be transparent and when collapsed it should be in the primary dark color).

Before the migration my theme was like that, so I did only define android:statusBarColor for theme overlays where I needed a transparent statusbar and everywhere else the statusbar was in the primary dark color by default.

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

After the migration I am working with the following, where I have to explicitly define android:statusBarColor in my base theme due to the following problem.

<resources>

    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryVariant">@color/colorPrimaryDark</item>
        <item name="colorSecondary">@color/colorAccent</item>

        <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
    </style>

    <style name="AppTheme.TransparentStatusBar">
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />

</resources>

But since there does not seem to be an implicit default anymore that means, that I get a blue (the Material Design default color) statusbar in all situations where I apply the AppTheme.TransparentStatusBar theme.

For example I have a transparent status bar when my CollapsingToolbarLayout is expanded (as expected), but a blue status bar when it is collapsed (I would expect it to be at least a color from my base theme by default).

toolbar expanded

toolbar collapsed

Is there a way to work around this problem?

flauschtrud
  • 690
  • 7
  • 23
  • Having the same problem. If you follow the steps noted here: https://developer.android.com/develop/ui/views/layout/edge-to-edge#change-color and set `@android:color/transparent` in the app's theme, the app doesn't honor it and it still applies a material3 color which we don't want. – 500865 Jun 21 '23 at 06:17

1 Answers1

1

I found a partial solution to fix at least my problem with the CollapsingToolbarLayout: when I add app:statusBarScrim="?attr/colorPrimaryVariant" to its definition I can restore the look from before my theme migration, i.e. I have the transparent statusbar according to my theme in the expanded state and the scrim color in the collapsed state.

I will leave the question open in case someone has an idea for a more global fix, since I still have other problems with a transparent status bar. For instance I am still not able to achieve a DrawerLayout that blends nicely under a transparent statusbar.

flauschtrud
  • 690
  • 7
  • 23