Using windowTranslucentStatus with a hidden toolbar

I am trying to enable windowTranslucentStatus and AppBarLayout with Toolbar with app:layout_scrollFlags="scroll|enterAlways" mark app:layout_scrollFlags="scroll|enterAlways"

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

Case study

The problem is the highest API where the toolbar is partially visible in the status bar. I tried many combinations of styles, but this is the closest I got.

In the styles that 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 xml layout:

 <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 an example application that is available on github

Is there anything in this puzzle?

+6
source share
3 answers

Fixed. This may not be the most beautiful solution, but it is wokrs (tested on 19 and 22). I added a negative margin to the layout of the coordinator and a positive margin to the toolbar (25 dp, since 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

+4
source

I installed it with customization

 android:fitsSystemWindows="false" on CoordinatorLayout. 

Hope this helps too!

+1
source

Have you tried putting the following into a RecyclerView ?

 app:layout_behavior="@string/appbar_scrolling_view_behavior" 

I think he needs to work with CoordinatorLayout . Also check if the version of com.android.support:recyclerview-v7 updated.

0
source

All Articles