divyanshu bhargava
divyanshu bhargava

Reputation: 1585

Cannot get elevation in BottomAppBar

How can I get the elevation for BottomAppBar. I think by default it has elevation as 8dp but I'm not getting any elevation. Here's my code.

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottom_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_gravity="bottom"
        style="@style/Widget.MaterialComponents.BottomAppBar" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/bottom_bar"
        android:src="@android:drawable/ic_input_add"
        android:tint="@color/colorPrimary"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Upvotes: 1

Views: 1022

Answers (1)

Cameron Ketcham
Cameron Ketcham

Reputation: 8006

Part of the problem is the way the lighting system works on Android. There is a light source from the top and a light source directly in the middle. This means shadows are generally not visible on top of Views.

We have a bug to fake the shadow for the BottomAppBar, but it's not as trivial as BottomNavigation for instance because the fab can move and change shape, so the shadow should change as well.

Upvotes: 2

Related Questions