Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar scrolling under status bar

I am trying to learn CoordinatorLayout and its features. I have used it in conjunction with AppBarLayout. My xml is as follows:

<android.support.design.widget.CoordinatorLayout

android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        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:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_gravity="bottom|end"
        style="@style/FabStyle"/>

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

The problem I am facing is that the toolbar on scrolling goes underneath the status bar. I want the toolbar to scroll when I scroll the Recycler View but I dont want it to go under the status bar. How do I prevent this from happening.

Also, When I try to encapsulate the CoordinatorLayout inside another layout eg: LinearLayout, the primaryDark color defined in theme does not showup in the status bar. It shows the primaryDark color when I use it as above xml. Is there a better way to do this?

like image 664
Roadblock Avatar asked Aug 18 '15 14:08

Roadblock


People also ask

What is AppBarLayout?

AppBarLayout is a vertical LinearLayout which implements many of the features of material designs app bar concept, namely scrolling gestures. Children should provide their desired scrolling behavior through AppBarLayout.

How to hide StatusBar in android studio?

Hide the Status Bar on Android 4.View decorView = getWindow(). getDecorView(); // Hide the status bar. // status bar is hidden, so hide that too if necessary.


1 Answers

I fixed this by going into the style that controls the status bar color and changed it to the color i wanted instead of transparent. Now it appears that the status bar is on top of the toolbar.

<resources>>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

`

<resources>>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>

like image 150
Ryan Johnston Avatar answered Sep 18 '22 00:09

Ryan Johnston