Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BottomNavigation style

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?

like image 603
faq700 Avatar asked Feb 12 '18 10:02

faq700


1 Answers

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"/>
like image 188
Quang Le Avatar answered Oct 12 '22 14:10

Quang Le