I took an example from https://habrahabr.ru/post/270121/ Link to the source code of the finished application https://github.com/saulmm/CoordinatorBehaviorExample

The source was completely copied, but a white stripe appeared on top. I can not understand how to change the color.

enter image description here

If in CoordinatorLayout add

android:fitsSystemWindows="true" 

That color remains, but in this case, it scrolls upward and a part of the image is visible at the top.

enter image description here

Although the top should stay in place and the image should pass under it

enter image description here

Source:

 <?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" xmlns:tools="http://schemas.android.com/tools" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent" tools:ignore="RtlHardcoded" tools:context="net.artsait.slideimg.MainActivity"> <android.support.design.widget.AppBarLayout android:id="@+id/main.appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/main.collapsing" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" > <ImageView android:id="@+id/main.imageview.placeholder" android:layout_width="match_parent" android:layout_height="300dp" android:scaleType="centerCrop" android:src="@drawable/quila2" android:tint="#11000000" app:layout_collapseMode="parallax" app:layout_collapseParallaxMultiplier="0.9" /> <FrameLayout android:id="@+id/main.framelayout.title" android:layout_width="match_parent" android:layout_height="100dp" android:layout_gravity="bottom|center_horizontal" android:background="@color/colorPrimary" android:orientation="vertical" app:layout_collapseMode="parallax" app:layout_collapseParallaxMultiplier="0.3" > <LinearLayout android:id="@+id/main.linearlayout.title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:gravity="bottom|center" android:text="@string/quila_name" android:textColor="@android:color/white" android:textSize="30sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="4dp" android:text="@string/quila_tagline" android:textColor="@android:color/white" /> </LinearLayout> </FrameLayout> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none" app:behavior_overlapTop="30dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" > <android.support.v7.widget.CardView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="8dp" app:cardElevation="8dp" app:contentPadding="16dp" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:lineSpacingExtra="8dp" android:text="@string/lorem" android:textSize="18sp" /> </android.support.v7.widget.CardView> </android.support.v4.widget.NestedScrollView> <include layout="@layout/content_main" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" app:srcCompat="@android:drawable/ic_dialog_email" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_anchor="@id/main.framelayout.title" app:popupTheme="@style/AppTheme.AppBarOverlay" app:title=""> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="horizontal" > <Space android:layout_width="@dimen/image_final_width" android:layout_height="@dimen/image_final_width" /> <TextView android:id="@+id/main.textview.title" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="8dp" android:gravity="center_vertical" android:text="@string/quila_name2" android:textColor="@android:color/white" android:textSize="20sp" /> </LinearLayout> </android.support.v7.widget.Toolbar> <de.hdodenhof.circleimageview.CircleImageView android:layout_width="@dimen/image_width" android:layout_height="@dimen/image_width" android:layout_gravity="center_horizontal" android:src="@drawable/quila" app:border_color="@android:color/white" app:border_width="2dp" app:finalHeight="@dimen/image_final_width" app:finalYPosition="2dp" app:layout_behavior="net.artsait.slideimg.AvatarImageBehavior" app:startHeight="2dp" app:startToolbarPosition="2dp" app:startXPosition="2dp" /> </android.support.design.widget.CoordinatorLayout> 

    2 answers 2

    Maybe your statusBar transparent, try changing its color:

    Powered by Api level> = 21

     if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { Window window = activity.getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(activity.getResources().getColor(R.color.youtBackgroundColor)); } 
    • Maybe I misunderstood something? I wrote the code in onCreate Before the code I wrote MainActivity activity; Now in the first line underlines the red activity and in the last setStatusBarColor - Artsait
    • If you hover over setStatusBarColor, then Call Call API Shows 21 (current min is 19): android.view.Window # setStatusBarColor - Artsait
    • replace with getApplicationContext () - Kirill Stoianov
    • aah yes, it works on api level> = 21 - Kirill Stoianov
    • api level? So far I have nothing to talk about)) I understand it will not work for me? - Artsait

    Found solutions, at the same time you can change the color of the navigation

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(getResources().getColor(R.color.primaryDark)); window.setNavigationBarColor(Color.BLUE); }