In this example we set the title and navigationIcon [back button] and also we set the color and elevation. In content area, we set the Column with one Text[].
Output:
Title customization:
You can customize the title area like this,
title = {
Row[] {
Text[
text = "Title 1",
fontSize = 30.sp,
color = Color.Red
]
Text[
text = "Title 2",
fontSize = 30.sp,
color = Color.White
]
}
}title - It accept any composable. Here we use the Row[] with two different Text[]
Output:
BottomNavigation
We can show bottom menu items with help of BottomNavigation. It make it easy for users to explore and switch between top-level views in a single tap.
If you are an Android developer, It's BottomNavigationView
Structure of BottomNavigation:
BottomNavigation[
modifier = //your modifier ,
backgroundColor = //color code,
contentColor = //color code,
elevation = //your elevation value in Dp
] { BottomNavigationItem1[]
BottomNavigationItem2[]
BottomNavigationItem3[]
.......
} Structure of BottomNavigationItem:
BottomNavigationItem[icon = {
//composable function for menu icon
},
label = { //composable function for menu title},
selected = //mutableState boolean for highlight,
onClick = {
//menu item click event
}]
BottomNavigation sample code
Step 1 : Create a composable function for BottomNavigation
@Composable fun BottomBar[] {
val selectedIndex = remember { mutableStateOf[0] }
BottomNavigation[elevation = 10.dp] {
BottomNavigationItem[icon = {
Icon[imageVector = Icons.Default.Home,""]
},
label = { Text[text = "Home"] },
selected = [selectedIndex.value == 0],
onClick = {
selectedIndex.value = 0
}]
BottomNavigationItem[icon = {
Icon[imageVector = Icons.Default.Favorite,""]
},
label = { Text[text = "Favorite"] },
selected = [selectedIndex.value == 1],
onClick = {
selectedIndex.value = 1
}]
BottomNavigationItem[icon = {
Icon[imageVector = Icons.Default.Person,""]
},
label = { Text[text = "Profile"] },
selected = [selectedIndex.value == 2],
onClick = {
selectedIndex.value = 2
}]
}
}Step 2: Add into Scaffold
@Composable fun ScaffoldWithBottomMenu[] {
Scaffold[bottomBar = {BottomBar[]}
] {
//content area
Box[modifier = Modifier
.background[Color[0xff546e7a]]
.fillMaxSize[]]
}
}Output:
Source code:
//github.com/JetpackCompose/Jetpack-Compose-Samples/blob/master/JetPackComposeSamples/app/src/main/java/net/jetpackcompose/composetext/activities/ActivityScaffold.kt
How do bottom navigation bars work in Android?
The material design team at Google defines the functionality of bottom navigation bars in Android as follows: Bottom navigation bars make it easy to explore and switch between top-level views in a single tap. Tapping on a bottom navigation icon takes you directly to the associated view or refreshes the currently active view.
How do I customize the bottom navigation view?
The bottom navigation view also can be customized with several different options, including: app:itemBackground, app:itemIcontint, and app:ItemTextColor: app:itemIconTint - The tinting for the bottom navigation's items' icons app:itemTextColor - The text color for the bottom navigation's items' text
How do I bootstrap a project with a bottom navigation bar?
As a bonus, you'll also learn how to use Android Studio templates to bootstrap your project with a bottom navigation bar quickly. Open Android Studio, create a new project, and select a Blank Activity template, as shown below. Select the Kotlin language from the drop-down menu and click Finish.
How do I notified when a bottom navigation item is selected?
Set a listener that will be notified when a bottom navigation item is selected. This listener will also be notified when the currently selected item is reselected, unless an BottomNavigationView.OnNavigationItemReselectedListener has also been set.
How to set border bottom in android studio?
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project..
Step 2 − Add the following code to res/drawable/border_top_bottom.xml