question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CollapsingToolbarLayout] DarkTheme wrong toolbar background color

See original GitHub issue

Description: I have CollapsingToolbarLayout with a toolbar that is always pinned to top and a collapsible view. The toolbar’s background color based on the toolbar elevation in dark mode is not applied, before collapsing and after collapsing.

Before collapsing: Screenshot_1569108212

After collapsing: Screenshot_1569108265

Expected behavior: Toolbar’s background to be lighter than the background based on it’s elevation

Source code:

<com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:titleEnabled="false"
            app:contentScrim="?attr/colorSurface"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <View
                android:layout_width="match_parent"
                android:layout_marginTop="?attr/actionBarSize"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/holo_orange_dark" />

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>

        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

Android API version: 28

Material Library version: 1.1.0-alpha010

Device: Android Emulator

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
cketchamcommented, Feb 14, 2020

It looks like we should check to see if we can apply the elevation overlay color to the content scrim.

1reaction
burhankhanzadacommented, Mar 31, 2020

Maybe it’s late but I solve my problem with first check is dark mode active by using this method

    fun isDarkTheme(context: Context): Boolean {
        return context.resources.configuration.uiMode and
                Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
    }

then setting the collapsingToolbarLayout.setContentScrimColor to elevation overlayed color like this

val collapsingToolbarLayout = findViewById<CollapsingToolbarLayout(R.id.collapsingToolbarLayout)

if (ThemeUtil.isDarkTheme(this@DetailActivity)) {
                        collapsingToolbarLayout!!.setContentScrimColor(
                            ElevationOverlayProvider(this@DetailActivity)
                                .compositeOverlayWithThemeSurfaceColorIfNeeded(4f)
                        )
                    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Collapsing toolbar changes color in night mode - Stack Overflow
MaterialComponents as a parent for dark theme. For some reason it uses colorOnSurface for toolbar color instead of colorPrimary.
Read more >
How to Collapse Toolbar Layout in Android? - GeeksforGeeks
I am using Dark theme for AppBarLayout. Inside this AppBarLayout i. have used CollapsingToolbarLayout. -->. < ...
Read more >
Collapsing Toolbar with Image - Android Studio Tutorial
In this tutorial, we will learn how to implement a collapsing toolbar with an expandable image into our Android app.
Read more >
App bars: top - Material Design
When a top app bar transforms into a contextual action bar, the following changes occur: The bar color changes; Navigation icon is replaced...
Read more >
MaterialToolbar - Android Developers
Regarding the Dark Theme elevation overlays, it's important to note ... While a MaterialToolbar with a transparent background can be used ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found