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 transition issue

See original GitHub issue

Description: CollapsingToolbarLayout collapse transition is not working properly in Material 3, tested on multiple device. Notice how the Toolbar color went solid immediately instead of having some fade effect like the first example.

Expected behavior:

Expected ezgif com-optimize

Actual

https://user-images.githubusercontent.com/38008900/168493911-f4a1f8fa-b851-4eaf-8757-0bbfd5b64d07.mp4

Source code:

Activity

<com.google.android.material.appbar.AppBarLayout
     android:id="@+id/appBar"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:fitsSystemWindows="true">

     <com.google.android.material.appbar.CollapsingToolbarLayout
         android:id="@+id/collapsingToolbar"
         android:layout_width="match_parent"
         android:layout_height="?attr/collapsingToolbarLayoutLargeSize"
         android:fitsSystemWindows="true"
         app:contentScrim="?attr/colorPrimary"
         app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
         app:maxLines="3">

         <androidx.appcompat.widget.AppCompatImageView
             android:id="@+id/featuredImage"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:adjustViewBounds="true"
             android:fitsSystemWindows="true"
             android:scaleType="centerCrop"
             app:layout_collapseMode="parallax" />

         <com.google.android.material.appbar.MaterialToolbar
             android:id="@+id/toolbar"
             android:layout_width="match_parent"
             android:layout_height="?attr/actionBarSize"
             android:minHeight="?attr/actionBarSize"
             android:paddingStart="0dp"
             android:paddingEnd="10dp"
             app:contentInsetEnd="0dp"
             app:contentInsetStart="0dp"
             app:contentInsetStartWithNavigation="0dp"
             app:layout_collapseMode="pin"
             app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
             app:title="@string/vwap" />

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

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

Theme

<style name="Theme.Cryptonian" parent="Theme.Material3.DayNight">
      <item name="collapsingToolbarLayoutStyle">@style/AppCollapsingToolbar</item>
</style>

Style

<!-- CollapsingToolbar style on both light and night mode -->
   <style name="AppCollapsingToolbar" parent="Widget.Material3.CollapsingToolbar" tools:keep="@style/AppCollapsingToolbar">
       <item name="expandedTitleTextColor">@android:color/white</item>
       <item name="statusBarScrim">@color/colorGray_PrimaryDark</item>
       <item name="collapsedTitleTextAppearance">@style/TextAppearance.App.CollapsingToolbar.Collapsed</item>
       <item name="expandedTitleTextAppearance">@style/TextAppearance.App.CollapsingToolbar.Expanded</item>>
   </style>

   <style name="TextAppearance.App.CollapsingToolbar.Expanded" parent="TextAppearance.MaterialComponents.Headline5" tools:keep="@style/TextAppearance_App_CollapsingToolbar_Expanded">
       <item name="android:textSize">18sp</item>
       <item name="android:shadowRadius">4</item>
       <item name="android:shadowDy">1</item>
       <item name="android:shadowColor">@android:color/black</item>
   </style>

   <style name="TextAppearance.App.CollapsingToolbar.Collapsed" parent="TextAppearance.MaterialComponents.Headline6" tools:keep="@style/TextAppearance_App_CollapsingToolbar_Collapsed">
       <item name="android:textSize">16sp</item> <!-- Reset -->
       <item name="android:textColor">@color/colorPrimaryDark_White</item>
   </style>

Android API version: SDK 21 and above

Material Library version: 1.7.0-alpha01

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dsn5ftcommented, Jun 6, 2022

@ArcherEmiya05 the behavior you’re seeing is actually consistent with the new M3 spec, which involves collapsing to show a toolbar color fill at the top.

This new effect is achieved in the M3 Top App Bar styles mainly via AppBarLayout app:liftOnScroll=“true” and CollapsingToolbarLayout app:titleCollapseMode=“fade”.

So to get more of an M2 collapsing toolbar I would probably try setting app:liftOnScroll="false" on your AppBarLayout and titleCollapseMode="scale" on your CollapsingToolbarLayout.

Here is the full list of M3 AppBarLayout/CollapsingToolbarLayout default attributes. Feel free to reopen if this doesn’t help.

0reactions
ArcherEmiya05commented, Jun 7, 2022

@ArcherEmiya05 the behavior you’re seeing is actually consistent with the new M3 spec, which involves collapsing to show a toolbar color fill at the top.

This new effect is achieved in the M3 Top App Bar styles mainly via AppBarLayout app:liftOnScroll=“true” and CollapsingToolbarLayout app:titleCollapseMode=“fade”.

So to get more of an M2 collapsing toolbar I would probably try setting app:liftOnScroll="false" on your AppBarLayout and titleCollapseMode="scale" on your CollapsingToolbarLayout.

Here is the full list of M3 AppBarLayout/CollapsingToolbarLayout default attributes. Feel free to reopen if this doesn’t help.

Thanks a lot, modifying scrimAnimationDuration also helps

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android complex collapsing toolbar transition - Stack Overflow
one solution is using MotionLayout and customizing it to have a collapsing toolbar layout behavior. this way the transition is very smooth.
Read more >
[CollapsingToolbarLayout] Slight misalignment during ...
Upon closer inspection of the new implementation, I found that there is a slight misalignment in the positions of the expanded text and...
Read more >
How to Disable Default CollapsingToolbarLayout Animation
This article described to you how you can disable the CollapsingToolbarLayout default Faddeing Animation. I hope this article is helpful. If you think...
Read more >
CollapsingToolbarLayout - Android Developers
A full-bleed scrim which is show or hidden when the scroll position has hit a certain threshold. You can change this via setContentScrim( ......
Read more >
MotionLayout — Collapsing Toolbar | by Mr Umbrella
MotionLayout provides far great flexibility and, a far easier path to achieving what you want without having a knowledge about Android Animation ......
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