1

I want to implement colored BottomNavigationView with elevation (current design lib version 25.2.0, test device 7.1.2). Some code for start:

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:elevation="8dp"
    app:elevation="8dp"
    app:menu="@menu/bottom_navigation" />

elevation (shadow) is not drawn, because there is no background. and there is known issue that this background must be white... ok, so I'm adding this line

    android:background="@android:color/white"

but I wanted to set some color for background and white icons and text... with below lines

    app:itemIconTint="@color/white"
    app:itemTextColor="@color/white"

whole bar is solid white, including content, obviusly... so if background must be white also then lets change every item background with

    app:itemBackground="@drawable/bottom_navigation_item_background"

and for drawable/

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/mycolor_dark"/>
    <item android:drawable="@color/mycolor"/>
</selector>

for drawable-v21/ (ripple)

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@android:color/white">
    <item android:drawable="@color/mycolor"/>
</ripple>

and now we have colored items and... no elevation again! and it will work when mycolor will be white (elevation shown/drawn)... so when I want elevation for BottomNavigationView both background and itemBackground must be white...

interesting part (proof of issue?) - lets check elevation with only this selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@android:color/white"/>
    <item android:drawable="@color/mycolor"/>
</selector>

bar is drawn without elevation at all, but when I press any menu item then its background change to white and... there is elevation above this item, ONLY this item!

when I remove <item android:drawable="@color/mycolor"/> line from drawable-v21/ XML file (or set mycolor to white), then elevation is shown. ripple color have no impact, it might be white or any other (working).

the question is: how to style BottomNavigationView with custom color for background keeping elevation working?

Community
  • 1
  • 1
snachmsm
  • 17,866
  • 3
  • 32
  • 74

1 Answers1

0

I used app:theme="@style/AppTheme.PopupOverlay" in order to use my application colors. They are automatically set to them. For example, if your primary color is green, icons and text will be displayed in green. You need to keep white background and elevation...

Tim241
  • 143
  • 2
  • 13