I'm wondering how to add a button to a BottomNavigationView, I include it inside the BottomNavigationView. But it was a work around. I want to know how to do it correctly?
I'm looking to add a button in the middle of the BottomNavigationView if someone knows how, besides the way I did it, because every time I change the menu item the button flashes
xml(menu):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/app_home"
android:enabled="true"
android:icon="@drawable/home"
android:title="@string/home"/>
<item
android:id="@+id/app_calendar"
android:enabled="true"
android:icon="@drawable/calendar"
android:title="@string/calendar"
/>
<item
android:id="@+id/app_add"
android:enabled="true"
app:showAsAction="collapseActionView"
android:icon="@drawable/badd"
tools:ignore="MenuTitle" />
<item
android:id="@+id/app_graphics"
android:icon="@drawable/graphics"
android:enabled="true"
android:title="@string/graphics"
/>
<item
android:id="@+id/app_engine"
android:enabled="true"
android:icon="@drawable/engine"
android:title="@string/home"
/>
</menu>
Work around
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemIconTint="@color/bnv_tab_item_foreground"
app:itemTextColor="@color/bnv_tab_item_foreground"
android:background="@color/colorFooter"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_navigation_menu"
tools:ignore="MissingConstraints" >
<com.google.android.material.button.MaterialButton
android:id="@+id/btnAdc"
android:layout_width="76dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@menu/buttonadd"
android:gravity="center"
android:text="@string/add_btn"
android:textSize="25sp"
/>
</com.google.android.material.bottomnavigation.BottomNavigationView>
I have used imageView you can change to button as per your requirement
and in bottom_nav_menu you can write like this
Hope this answers your question.