I tried setting elevation from xml and programmatically both. But nothing works.
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!
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.
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...
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.
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" />
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