Bottom Navigation with Floating Action Button
1.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActvity">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bar"
style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:fitsSystemWindows="true"
app:fabAlignmentMode="center"
app:fabCradleRoundedCornerRadius="20dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
android:background="@android:color/transparent"
android:padding="0dp"
app:elevation="0dp"
app:itemIconTint="@drawable/bottom_navigation_selector"
app:itemTextColor="@drawable/bottom_navigation_selector"
app:menu="@menu/bottom_navigation" />
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="8dp"
android:src="@drawable/ic_plus"
app:layout_anchor="@id/bar"
app:rippleColor="@color/colorPrimary" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
2.bottom_navigation_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/black" android:state_checked="true" />
<item android:color="@android:color/darker_gray" />
</selector>
3.navigation menu items menu/bottom_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/home"
android:icon="@drawable/ic_home"
android:title="@string/home"
app:showAsAction="always"
/>
<item
android:id="@+id/myPackages"
android:icon="@drawable/ic_home"
android:title="@string/my_packages"
app:showAsAction="always"/>
<item
android:id="@+id/place"
android:title="" />
<item
android:id="@+id/myQuotations"
android:icon="@drawable/ic_home"
android:title="@string/quotations"
app:showAsAction="always"/>
<item
android:id="@+id/account"
android:icon="@drawable/ic_home"
android:title="@string/account"
app:showAsAction="always"/>
</menu>
4.In Main Actvity in onCreate() Add following code
bottomNavigation.getMenu().getItem(2).setEnabled(false); bottomNavigation.setOnNavigationItemSelectedListener(this);
