Coding Bihar

Android App Development

Coding Bihar is dedicated to providing you with the knowledge and tools you need to excel in Android development. Start your journey with us and transform your app ideas into reality with Jetpack Compose. Connect, learn, and grow with Coding Bihar today!

Navigation Rail in Jetpack Compose

Navigation Rail in Jetpack Compose - Coding Bihar
Navigation Rail in Jetpack Compose

How to create Navigation rail?

Navigation Rail is most useful components of Material Design if our apps are used on a device of larger screen such as tablet and desktop. It make easy for users to navigate. It looks like a sidebar and can contains three to seven app destination items. We use NavigationRailItem to represent a destination within a Navigation Rail.

It should be placed at the side edge of large screen devices such as tablets or desktop when an application has three to seven top-level destinations.

In this tutorial we will learn to create Navigation Rail.

Create a New Project and select Empty Activity In my case, application name is coding Bihar you can use any other name.


Copy this code →
package com.example.codingbihar

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.example.codingbihar.ui.theme.CodingBiharTheme

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        setContent {
            CodingBiharTheme {
                // A surface container using the 'background' color from the theme
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
Create a separate file for Navigation Rail and named it as NavigationRails


Copy this code →
package com.example.codingbihar

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationRail
import androidx.compose.material3.NavigationRailItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue

fun NavigationRails() {
        var selectedItem by remember { mutableStateOf(0) }
        val items = listOf("Home", "Search", "Settings")
        val icons = listOf(Icons.Filled.Home,
            Icons.Filled.Search, Icons.Filled.Settings)
    Row {
        NavigationRail {
            items.forEachIndexed { index, item ->
                    icon = { Icon(icons[index], contentDescription = item) },
                    label = { Text(item) },
                    selected = selectedItem == index,
                    onClick = { selectedItem = index }



 Sandeep Gupta

Posted by Sandeep Gupta

Please share your feedback us Thank you for being a part of our community!

Special Message

Welcome to coding bihar!