Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapsing toolbar - toolbar under statusbar

I've recently bumped to problem with coordinator layout. When I try to create simple collapsing toolbar layout as in this example, toolbar apears to be under status bar as in screenshot below (on preLolipop devices everything works fine, because app don't draw under under statusbar).

toolbar under statusbar (see back arrow)

Code snippet of my Activity layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/imageCalculationDetail"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@drawable/ic_dummy_calculation"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"/>

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

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include layout="@layout/container"/>

    </android.support.v4.widget.NestedScrollView>

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

My Styles (only v21) where BaseAppTheme parent is Theme.AppCompat.Light.NoActionBar:

<style name="AppTheme" parent="BaseAppTheme">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:colorAccent">@color/colorPrimary</item>
        <item name="android:colorButtonNormal">@color/button_state_list</item>
        <item name="android:statusBarColor">@color/transparent</item>
    </style>
like image 801
Jarda Havelik Avatar asked Sep 14 '16 14:09

Jarda Havelik


1 Answers

Well I figure it out, problem was that I had

<item name="android:fitsSystemWindows">true</item>

in my toolbarStyle of BaseAppTheme (for other actvities, everything works well, for collapsing toolbar with translucent status bar not). After setting

android:fitsSystemWindows="false"

to my toolbar, everything works fine.

like image 77
Jarda Havelik Avatar answered Dec 06 '22 04:12

Jarda Havelik