Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add elevation (shadow) to my BottomNavigationView. It doesn't come by default

I tried setting elevation from xml and programmatically both. But nothing works.enter image description here

like image 201
Javed Khatri Avatar asked Nov 23 '16 14:11

Javed Khatri


People also ask

Does bottomnavigationview have a shadow or elevation?

As we can see there is no fancy shadow or elevation : ( That Background Color! The BottomNavigationView is a tricky beast regardless if you are in Android XML or Xamarin.Forms. To get a drop shadow/elevation on it you MUST set the background color!

How to create a bottomnavigationview menu in Android?

Right-click on the res folder and select Android Resource Directory. Make sure to select the resource type as a menu . Now create the bottom_menu.xml file and add the following code. In this file, we add the title, id, and icon of our menu for BottomNavigationView . Below is the code for the bottom_menu.xml file.

What's new with Android elevation and drop shadows?

It is a tale as old of time fighting with Android elevation and drop shadows. First it was the Toolbar on a Navigation page and now it is the new fancy bottom tabs that we got in Xamarin.Forms 3.1. I know what you are thinking... another custom renderer...

How do I draw an indicator in bottomnavigationview?

By default the BottomNavigationView won’t call onDraw, so instead we put the drawing command in dispatchDraw. The command is simple, draw a rounded rect with the bounds of the indicator and with a corner radius that’s half the height of the indicator. This gives the indicator a pill shape while moving and a circle when it’s still.


1 Answers

It only works if you set white as android:background in the BottomNavigationView.

This is my code and it's working:

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@color/white"
    app:elevation="8dp"
    app:itemIconTint="@color/bottom_color_state"
    app:itemTextColor="@color/bottom_color_state"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.52"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/bottom_navigation_main" />
like image 106
nellorocca Avatar answered Sep 19 '22 12:09

nellorocca