Search code examples
androidandroid-toolbarandroid-coordinatorlayoutandroid-framelayout

FrameLayout in CoordinatorLayout making toolbar-background transparent to white


Below is my code:-

  <android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbarlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent" />
    </android.support.design.widget.AppBarLayout>


    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appbarlayout"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />


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

this gives me transparent toolbar as expected, As below:- enter image description here But my Framelayout overlap on toolbar so I tried

  1. to give top margin to Framelayout

  2. using ' app:layout_behavior="@string/appbar_scrolling_view_behavior" '

this code worked and my FrameLayout is not overlaping but my toolbar is turning to white_color.

new Output is as below enter image description here

Please help !. what's making my toolbar to be white from transparent background.


Solution

  • This will work

    • Add a RelativeLayout and give background image to that
    • Inside that you can have AppBarLayout and FrameLayout with android:layout_below="@+id/appbarlayout"

    Example:

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:fitsSystemWindows="true">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/amanda">
    
            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbarlayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                app:elevation="0dp">
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="@android:color/transparent" />
            </android.support.design.widget.AppBarLayout>
    
    
            <FrameLayout
                android:id="@+id/content_frame"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/appbarlayout"
                android:background="#332"
                android:orientation="vertical" />
        </RelativeLayout>
    </android.support.design.widget.CoordinatorLayout>