BottomNavigation style

faq700 picture faq700 · Feb 12, 2018 · Viewed 9.4k times · Source

I have BottomNavigationView

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    app:itemTextColor="@color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    android:background="?android:attr/windowBackground"
    android:foreground="?attr/selectableItemBackground"
    app:itemIconTint="@android:color/white"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/navigation" />

when I use default styles in manifest everything is ok:

<application
    android:name=".model.MyApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">

enter image description here

When I override default styles like this

 <style name="base" parent="Theme.AppCompat.Light.NoActionBar" >
    <item name="android:background">@color/grey_dark_bg_md</item>
    <item name="android:textColor">@color/white</item>
</style>

and manifest:

    <application
    android:name=".model.MyApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/base">
    <activity
        android

I get problems. Non active bottom navigation images cuts

enter image description here

whats wrong with styles?

Answer

Quang Le picture Quang Le · Apr 26, 2019

You can set style for BottomNavigationView as below:

  1. Declare custom style in your styles.xml file.
<style name="BottomNavigation">
    <item name="android:background">@color/indigo</item>
    <item name="itemBackground">@drawable/navigation_bar_item_bg</item>
    <item name="itemIconTint">@color/navigation_bar_txt_color</item>
    <item name="itemTextColor">@color/navigation_bar_txt_color</item>
    <item name="paddingStart">@dimen/bottom_navigation_padding</item>
    <item name="paddingEnd">@dimen/bottom_navigation_padding</item>
</style>
  1. Apply this style to your BottomNavigationView via style attribute.
<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottomNavigationView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:menu="@menu/bottom_navigation_menu"
    style="@style/BottomNavigation"/>