Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent AppBarLayout

I'm developing an application where I'd like to have a transparent Toolbar (AppBarLayout), but still see the navigation icon button. Unfortunately, best I can achieve is transparent toolbar that still drops the shadow (elevation).

I have a full screen dialog fragment, see style:

<style name="FullScreenImageStyle" parent="AppTheme">
        <item name="android:windowNoTitle">true</item>

        <item name="android:windowFullscreen">false</item>
        <item name="android:windowIsFloating">false</item>


        <item name="android:windowEnterAnimation">@anim/slide_up</item>
        <item name="android:windowExitAnimation">@anim/slide_down</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="windowActionBarOverlay">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>

The layout for the fragment looks like this (only the beginning here):

<androidx.coordinatorlayout.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:fitsSystemWindows="true">

    <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent">

        <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

    </com.google.android.material.appbar.AppBarLayout>

Later when initializing the dialog fragment, I set the fullscreen style and the navigation icon's resource id.

The result looks like this. Note the toolbar's shadow on top of the screen: enter image description here

Any ideas how to solve the problem, please?

like image 271
Jakub Gruber Avatar asked Mar 28 '19 05:03

Jakub Gruber


People also ask

How do you make AppBarLayout transparent?

Simply use app:elevation="0dp" inside "AppBarLayout" to remove the shadow.

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 do I make my Android toolbar invisible?

The simplest way to put a Toolbar transparent is to define a opacity in @colors section, define a TransparentTheme in @styles section and then put these defines in your toolbar.


2 Answers

Use this code

 <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null">
appBarLayout.setOutlineProvider(null)
like image 118
Rafael Avatar answered Oct 06 '22 21:10

Rafael


Try this ;

 android:background="@color/transparent"
 android:elevation="0dp"
 app:elevation="0dp"

<color name="transparent">#00000000</color>
like image 20
Hasan Kucuk Avatar answered Oct 06 '22 21:10

Hasan Kucuk