Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar behind status bar with API 21

I've a fragment with a CoordinatorLayout

When i run the app with API 19 the behavior is right : The toolbar is below the status bar and the FAB button of the main_activity go away :

Api19

But with the API 21 and + : The toolbar is behind the status bar and the FAB button of the main_activity don't go away : Api21

Layout file:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/caves_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/caves_collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimaryDark"
            app:expandedTitleMarginStart="78dp"
            app:expandedTitleMarginEnd="124dp">

            <ImageView
                android:id="@+id/caves_backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:background="@drawable/drawer_header_bg"
                app:layout_collapseMode="parallax"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_horizontal">

            </LinearLayout>

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

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

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/caves_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/caves_fab"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        app:layout_anchor="@id/caves_appbar"
        app:layout_anchorGravity="bottom|right|end"
        android:src="@drawable/ic_discuss"
        android:layout_margin="@dimen/fab_margin"
        android:clickable="true"/>

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

I've add a specify style-v21 xml file

<resources>
    <style name="AppTheme" parent="Base.Theme.Design">
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowSharedElementsUseOverlay">false</item>
    </style>
</resources>

I'dont find and understand the problem.

like image 503
Selorbis Avatar asked Oct 25 '15 19:10

Selorbis


People also ask

What is the difference between the activity and status bar?

The activity is given a window where it draws the view hierarchy specified by us. The status bar is given a window where the system draws things like time, battery, notification icons etc. The navigation bar also has a different window where it draws the back button, the home button etc.

What is the difference between status bar and navigation bar?

The status bar is given a window where the system draws things like time, battery, notification icons etc. The navigation bar also has a different window where it draws the back button, the home button etc. All these windows on a single screen are managed by WindowManager. What are these different flags you can apply to a window?

How to make the status bar fully visible in light mode?

SYSTEM_UI_FLAG_LIGHT_STATUS_BAR makes sure that the status bar icons are drawn in such a way so that they are fully visible in light mode. Cool..so, now our status bar looks pretty good on most of the API levels. But but.. what's up with the Floating Action Button.

What is a status bar in Linux?

A status bar is a horizontal window at the bottom of a parent window in which an application can display various kinds of status information. Creates a status window, which is typically used to display the status of an application. The window generally appears at the bottom of the parent window, and it contains the specified text.


3 Answers

add android:fitsSystemWindows="false"to the CoordinatorLayout

like image 143
joseluelu Avatar answered Oct 18 '22 22:10

joseluelu


Had a similar problem (exemplified here)

How I made it work was to add android:fitsSystemWindows="false" to the AppBarLayout and have it on true on the CoordinatorLayout

like image 44
Matyas Avatar answered Oct 18 '22 21:10

Matyas


take off this line:

<item name="android:windowTranslucentStatus">true</item>
like image 32
Mohammed Aouf Zouag Avatar answered Oct 18 '22 21:10

Mohammed Aouf Zouag