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:
Any ideas how to solve the problem, please?
Simply use app:elevation="0dp" inside "AppBarLayout" to remove the shadow.
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.
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.
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)
Try this ;
android:background="@color/transparent"
android:elevation="0dp"
app:elevation="0dp"
<color name="transparent">#00000000</color>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With