Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using windowTranslucentStatus with hidden Toolbar

I'm trying to incorporate windowTranslucentStatus and AppBarLayout with Toolbar flagged with app:layout_scrollFlags="scroll|enterAlways"

Testing simultaneously on APIs 18, 19 and 22 (from the left).

Case study

Problem is on the highest API, where toolbar is partialy visible under the statusbar. I tried many many combinations of styles but this is the closest I got.

In styles I use:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:colorPrimary" tools:targetApi="lollipop">@color/primary</item>
    <item name="android:colorPrimaryDark" tools:targetApi="lollipop">@color/primary_dark</item>
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/primary</item>
    <item name="android:colorAccent" tools:targetApi="lollipop">@color/primary</item>
    <item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
    <item name="android:windowBackground">@color/background</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Here is my layout xml:

<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/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true">

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


<android.support.design.widget.FloatingActionButton
    android:id="@+id/add_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="@color/green"
    app:layout_anchor="@id/recycler_view"
    app:layout_anchorGravity="bottom|right|end" />

I created sample app, which is available on github

Is there something missing in this puzzle?

like image 466
Jacek Kwiecień Avatar asked Nov 08 '15 08:11

Jacek Kwiecień


2 Answers

Fixed it. It might not be the most beautiful solution, but it wokrs (tested on 19 and 22). I added a negative margin to the coordinator layout and a positive margin to the toolbar (25dp as this is the height of the status bar).

<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/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    android:layout_marginTop="-25dp">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:minHeight="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:layout_marginTop="25dp"/>

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/add_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="@color/green"
        app:layout_anchor="@id/recycler_view"
        app:layout_anchorGravity="bottom|right|end" />

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

enter image description here

like image 127
crysxd Avatar answered Sep 30 '22 18:09

crysxd


I fixed it with setting

android:fitsSystemWindows="false" on CoordinatorLayout.

Hope that helps you also !

like image 38
Wim Winterberg Avatar answered Sep 30 '22 19:09

Wim Winterberg