Res/menu- bottom_navigation_menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_home"
android:title="Home"
android:icon="@drawable/in_home" />
<item
android:id="@+id/navigation_dashboard"
android:title="Dashboard"
android:icon="@drawable/ic_desbord" />
<item
android:id="@+id/navigation_notifications"
android:title="Notifications"
android:icon="@drawable/may_now" />
</menu>
Res/Drawable- item_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#00F40A"/>
<item android:color="#328E2A"/>
</selector>
Res/Values/themes- thames.xml
<style name="Widget.MaterialComponents.BottomNavigationView.Colored">
<item name="android:clickable">true </item>
<item name="backgroundTint">#000000 </item>
<item name="colorControlNormal">#17B810 </item>
<item name="itemTextColor">#00F40A </item>
</style>
BottomNavigationView - XML Code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity"
android:background="#E4EEED"
>
<!-- Bottom Navigation View -->
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
app:menu="@menu/bottom_navigation_menu"
style="@style/Widget.MaterialComponents.BottomNavigationView.PrimarySurface"
app:itemRippleColor="#DD0800FD"
android:keyboardNavigationCluster="true"
app:itemTextAppearanceActiveBoldEnabled="true"
app:itemIconSize="20dp"
app:itemIconTint="@drawable/item_selector"
android:clickable="true"
android:background="@color/black"
app:itemTextColor="#00F40A"
android:foreground="?attr/selectableItemBackground"
/>
</RelativeLayout>
BottomNavigationView - Java Code
package com.arahlab.bottomnavig;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class MainActivity extends AppCompatActivity {
BottomNavigationView bottomNavView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bottomNavView = findViewById(R.id.bottomNavView);
bottomNavView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
if (item.getItemId()==R.id.navigation_home){
Toast.makeText(MainActivity.this, "Home", Toast.LENGTH_SHORT).show();
}else if (item.getItemId()==R.id.navigation_dashboard){
Toast.makeText(MainActivity.this, "Dashboard", Toast.LENGTH_SHORT).show();
}else if (item.getItemId()==R.id.navigation_notifications){
Toast.makeText(MainActivity.this, "Notification", Toast.LENGTH_SHORT).show();
}
return true;
}
});
}
}