12

I'm using the following layout and it works great on all versions except Android Nougat where the title gets cut off when fully collapsed.

enter image description here

<android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/them_color"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/header_image"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:contentDescription="@string/app_name"
                android:fitsSystemWindows="true"
                android:scaleType="fitXY"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?android:attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:contentInsetLeft="0dp"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        </android.support.design.widget.CollapsingToolbarLayout>

I have tried app:collapsedTitleGravity="center" but it doesn't fix the issue. How can I make it work on Nougat?

user
  • 86,916
  • 18
  • 197
  • 190
user2881604
  • 2,330
  • 3
  • 21
  • 38

4 Answers4

13

Issue is reported.

There is even better option than removing fitsSystemWindows, just add to onCreate collapsingToolbarLayout.post { collapsingToolbarLayout.requestLayout() }

panbacuh
  • 622
  • 1
  • 9
  • 17
  • Thanks for mentioning this and especially the fix but please note that your post-block won't work without a `Runnable`. – reVerse May 07 '17 at 15:13
9

removing android:fitsSystemWindows="true" solved my problem

Peter
  • 1,069
  • 2
  • 13
  • 24
2

This Sample project shows how to implement collapsing toolbar in Android.

Ashwin
  • 7,277
  • 1
  • 48
  • 70
1

Posting requestLayout in a runnable didn't work for me but if you're using AppCompatActivity you can use setSupportActionBar with the toolbar which seems to work.

Mateo
  • 519
  • 4
  • 4