Build a Bottom Navigation Bar in Android with Fragments

A bottom navigation bar is a practical way to give an Android app several primary destinations without crowding the screen. In a fragment-based implementation, the activity stays in charge of navigation while each tab displays its own Fragment. This arrangement keeps screen code focused, supports independent tab state, and makes visual changes easier to apply consistently.

Material 3’s BottomNavigationView and AndroidX Navigation provide the standard route to this architecture. Together, they handle destination selection, fragment transactions, back stacks and saved state. The resulting app has one clear navigation owner while each screen retains the logic and resources it needs.

Plan the destinations before writing fragments

Start by choosing the app’s primary sections. Four destinations—Home, Activity, Alerts and Profile—are comfortable within the material design guidance for bottom navigation. Give each destination a short label that makes sense without relying on its icon, and create a unique fragment class and layout for it. The activity should coordinate these screens rather than containing their business logic.

Use View Binding to access the activity layout safely and add the Material Components, Navigation Fragment and Navigation UI dependencies through the project’s version catalogue. The navigation graph will connect the activity to every destination, while a menu resource will supply the visible tabs. This division gives each resource one job and avoids the common problem of manually replacing fragments with overlapping transactions.

Lay out the navigation shell

Place the navigation host and bottom bar inside a ConstraintLayout. The host fills the space above the bar, while the bar remains attached to the bottom of the activity:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_navigation_menu" />

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/main_navigation" />

</androidx.constraintlayout.widget.ConstraintLayout>

The graph must use the same fragment class names as the app. Its start destination becomes the screen shown when the activity launches:

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_navigation"
    app:startDestination="@id/homeFragment">

    <fragment
        android:id="@+id/homeFragment"
        android:name="com.example.app.HomeFragment"
        android:label="@string/home" />

    <fragment
        android:id="@+id/activityFragment"
        android:name="com.example.app.ActivityFragment"
        android:label="@string/activity" />

</navigation>

Define homeFragment, activityFragment and the other IDs consistently across the graph and menu. That exact match allows Navigation UI to map each selected menu item to a destination without custom click handling.

Build fragments for each destination

Each tab should have an ordinary fragment class with its own layout. A simple destination can inflate a resource layout directly:

class HomeFragment : Fragment(R.layout.fragment_home) {
    override fun onViewCreated(
        view: View,
        savedInstanceState: Bundle?
    ) {
        super.onViewCreated(view, savedInstanceState)
        view.findViewById<TextView>(R.id.home_heading).text =
            getString(R.string.home_heading)
    }
}

Keep screen-specific requests, filtering and state in a fragment-scoped ViewModel. When a tab loads server content, expose loading, empty and error states rather than blocking navigation. This backend navigation endpoints guide shows a Spring Boot approach for supplying data while the Android layer remains focused on presentation.

Avoid giving every fragment direct access to the activity’s navigation host. The fragment should request an action through its NavController, while the graph defines where that action leads. This keeps navigation testable and prevents a screen from becoming coupled to a particular activity implementation.

Connect menu selections to destinations

Create the bottom navigation menu with the same IDs used by the navigation graph:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/homeFragment"
        android:icon="@drawable/ic_home"
        android:title="@string/home" />
    <item
        android:id="@+id/activityFragment"
        android:icon="@drawable/ic_activity"
        android:title="@string/activity" />
    <item
        android:id="@+id/alertsFragment"
        android:icon="@drawable/ic_alerts"
        android:title="@string/alerts" />
    <item
        android:id="@+id/profileFragment"
        android:icon="@drawable/ic_profile"
        android:title="@string/profile" />
</menu>

Inflate the activity layout and connect the menu to the graph controller in MainActivity:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    val binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

    val navHost =
        supportFragmentManager.findFragmentById(R.id.nav_host_fragment)
            as NavHostFragment

    binding.bottomNavigation.setupWithNavController(navHost.navController)
}

setupWithNavController performs the navigation and manages each top-level destination’s state. Listen for destination changes if the activity title, toolbar or badge count needs to change. A badge showing unread alerts, for example, can be updated when alertsFragment becomes active.

Preserve tabs, state and back behaviour

Android may recreate an activity after rotation or process death, so a tab should not depend on an old fragment instance remaining in memory. Store durable values in a ViewModel and SavedStateHandle, and let the navigation component restore the destination stack. Form text, filters and scroll positions can then return to the screen where the user left them.

Back-stack behaviour also needs deliberate testing. Returning from a detail screen should lead to its parent tab, while pressing back from a top-level tab should follow the activity’s expected exit behaviour. Navigation options such as launchSingleTop, restoreState and popUpTo can prevent duplicate entries and preserve independent stacks, but they are only necessary when handling selections outside the standard setupWithNavController flow.

Do not imitate this system by calling replace() whenever a tab changes. Such an approach usually discards the previous screen, complicates restoration and produces incorrect results when the activity is recreated. Keep all destination changes inside the navigation graph so deep links, arguments and back-stack rules work consistently.

Polish the experience for Australian users

Commuters often use apps with one hand while boarding trains in Sydney or hopping onto trams in Melbourne. Place compact actions within comfortable thumb reach, retain visible tab labels and avoid animations that delay a response. The bar should also respect edge-to-edge system insets, particularly on devices with gesture navigation or a cut-out display.

Motion can clarify a selection, but restraint usually produces the better result. This MotionLayout animation example demonstrates how to coordinate visual properties for a transition or indicator without making every tab movement feel busy. Use the selected-item tint and a brief transition as the primary feedback.

Regional users may encounter patchy mobile coverage outside the major capitals, so keep payloads small, cache useful data and show a clear offline state. Australian English also matters: labels using words such as “Favourites” and “Organisation” should match local expectations. Check large font settings, sunlight contrast, TalkBack output and the minimum 48dp touch targets before release.

Test and ship the app

Test every transition from the first screen, including repeated taps, rotation, process recreation, back navigation and opening a destination through a deep link. Automated navigation tests can verify that the graph reaches the expected destination and arguments. Instrumented tests are especially useful for confirming that each tab restores its data without leaking state from another tab.

Australia’s Android audience receives updates through Google Play, so a staged rollout can reveal layout or compatibility issues before the change reaches every device. Check Play Console for crash reports, and confirm that any paid features use Australian-dollar pricing through Google Play Billing. Release notes should also be clear about permissions and account changes.

Build the navigation shell now, connect the four fragment destinations, test the complete back-stack behaviour on real devices, and publish the first version to Australian users through Google Play.