BottomNavigationView

bottommenu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/home"
android:icon="@drawable/home"
android:title="home" />

<item
android:id="@+id/settings"
android:icon="@drawable/settings"
android:title="settings" />

<item
android:id="@+id/about"
android:icon="@drawable/info"
android:title="about" />

</menu>


 XML

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottommenu"/>


JAVA

bottomNavigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

int id = item.getItemId();
if (id == R.id.home) {
Toast.makeText(BottomNavigationActivity.this, "Home", Toast.LENGTH_SHORT).show();
} else if (id == R.id.settings) {
Toast.makeText(BottomNavigationActivity.this, "Settings", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(BottomNavigationActivity.this, "About", Toast.LENGTH_SHORT).show();
}
return true;
}
});


OUTPUT

Post a Comment

Previous Post Next Post