I want to add a line below each name of the items. How can I do this with bottom navigation view? The image has an orange line below the item name. So It should be visible for the selected item only. I have done with the Linear layout. I need to do with the bottom navigation view.
Please check with this image. I did with selector functions for this
attribute app:itemBackground="@drawable/selector"
For do this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:right="20dp"
android:left="20dp">
<shape>
<stroke
android:width="4dp"
android:color="@color/bottom_sheet_divider" />
<solid android:color="@color/transparent" />
</shape>
</item>
<item
android:bottom="4dp">
<shape>
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
</shape>
</item>
<item android:top="-41dp" android:right="-41dp" android:left="-41dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke
android:width="4dp"
android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/line_selected" android:state_checked="true"/>
<item android:drawable="@drawable/line_unselected" android:state_checked="false"/>
</selector>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
---> app:itemBackground="@drawable/item_line"
app:menu="@menu/bottom_navigation_menu" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.