0

I have created a BottomNavigationView with 4 menus. Somehow its not setting the background color to cover the text and icon. See the screenshot, the text and image are still showing the white background

<style name="BottomNavigationView" parent="">
    <item name="labelVisibilityMode">labeled</item>
    <item name="itemHorizontalTranslationEnabled">false</item>
    <item name="itemBackground">@android:color/holo_green_light</item>
    <item name="itemTextColor">@drawable/selector_bottom_bar_text</item>
    <item name="itemIconTint">@drawable/selector_bottom_bar_icon</item>
    <item name="itemTextAppearanceActive">@style/navTextActive</item>
    <item name="itemTextAppearanceInactive">@style/navTextInactive</item>
</style>


<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottomNav"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    style="@style/BottomNavigationView"

    app:menu="@menu/bottom_nav" />

enter image description here

  1. How to fix the text and iconbackground?
  2. How to add a bit of space between the icon and text?
Sibin S V
  • 26
  • 2
  • 1
    for 2 https://stackoverflow.com/questions/43386768/how-to-change-text-padding-in-android-bottom-navigation-view – IntelliJ Amiya May 01 '20 at 15:46
  • Spacing issue solved. Can you help me to fix the background – Sibin S V May 01 '20 at 16:03
  • 2
    Remove `android:background` from your *theme*. Everything that doesn't have a background (most things, here the icon and label views) will use that value. This is something you don't want to have in theme. Set `android:background` on individual views or in *view styles*. [Don't mix themes and styles.](https://stackoverflow.com/a/15170455/2444099) – Eugen Pechanec May 01 '20 at 16:33
  • Thanks. It worked. I was setting the background color in theme. That caused this. After removing the background from the theme it works correctly – Sibin S V May 04 '20 at 15:13

3 Answers3

0
    android:background="?android:attr/windowBackground"
    app:itemIconTint="@drawable/bg_navigation"
    app:itemTextColor="@drawable/bg_navigation"

Then create bg_navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false" android:color="hex_color_code" />
    <item android:state_checked="true" android:color="hex_color_code" />
</selector>

For Spacing issue, You can check this answer.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

I am not sure whether this will work. But, you can try adding this to your Activity.java file and see if it works. navigationView.setItemIconTintList(null); navigationView.setBackgroundTintList(null);

Sneha
  • 94
  • 10
0

Thanks to @Eugen Pechanec. It worked. I was setting the background color in theme. That caused this. After removing the background from the theme it works correctly

Sibin S V
  • 26
  • 2