Top app bars display information and actions at the top of a screen. This Top App Bar has slots for a title, navigation icon, and actions.
title - the title to be displayed in the top app bar.
navigation Icon - the navigation icon displayed at the start of the top app bar. This should typically be an Icon Button or Icon Toggle Button.
actions - the actions displayed at the end of the top app bar. This should typically be Icon Buttons. The default layout here is a Row, so icons inside will be placed horizontally.
Scaffold
The Scaffold widget implements the basic material design visual layout structure in a jetpack compose application. Scaffold widget provides API to insert several material components to construct app screen such as Top App Bar, Bottom App Bar, Floating Action Button, etc. So that, we can show a Floating Action Button in our jetpack compose application using the Scaffold ‘floating Action Button’ parameter. Simply we can pass a Floating Action Button instance to this parameter to show a floating action button on our mobile device screen.
Also Read How to create compose check box
MainAcivity.kt
package com.codingbihar.jetpackcomposeskill
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import com.codingbihar.jetpackcomposeskill.ui.theme.JetpackComposeSkillTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
JetpackComposeSkillTheme {
TopAppBarScreen()
}
}
}
}Top App Bar Screen
package com.codingbihar.jetpackcomposeskill
import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FabPosition
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.sp
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TopAppBarScreen(){
val result = remember { mutableStateOf("") }
val selectedItem = remember { mutableStateOf("share")}
val fabShape = RoundedCornerShape(50)
Scaffold(
topBar = {
TopAppBar(
title = {
Text(text = "Top App bar")
},
navigationIcon = {
IconButton(
onClick = {
result.value = "Drawer icon clicked"
}
) {
Icon(imageVector =Icons.Filled.Menu,
contentDescription = "")
}
},
)
},
content = {
Box(
Modifier
.background(Color(0XFFE3DAC9))
.padding(16.dp)
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(
text = result.value,
fontSize = 22.sp,
fontFamily = FontFamily.Serif
)
}
},
floatingActionButton = {
FloatingActionButton(
onClick = {result.value = "FAB clicked"},
shape = fabShape,
) { Icon(Icons.Filled.Add,"")
}
},
floatingActionButtonPosition = FabPosition.End,
bottomBar = {
BottomAppBar(
//cutoutShape = fabShape,
content = {
NavigationBarItem(
icon = {
Icon(Icons.Filled.Favorite , "")
},
label = { Text(text = "Favorite")},
selected = selectedItem.value == "favorite",
onClick = {
result.value = "Favorite icon clicked"
selectedItem.value = "favorite"
},
alwaysShowLabel = false
)
NavigationBarItem(
icon = {
Icon(Icons.Filled.Share , "")
},
label = { Text(text = "Share")},
selected = selectedItem.value == "share",
onClick = {
result.value = "Share icon clicked"
selectedItem.value = "share"
},
alwaysShowLabel = false
)
}
)
}
)
}OUTPUT :-
Explanation:
- result is used to display messages when buttons are clicked.
- selectedItem keeps track of which bottom navigation item is selected.
- TopAppBar: Displays a title and optional icons.
- Navigation Icon (IconButton): The hamburger menu icon on the left (clicking it updates result).
- Title (Text): Displays "Top App bar".
- Box: A simple layout to center its content.
- background(Color(0XFFE3DAC9)): Sets a light beige background.
- Inside Box: A Text widget shows messages when the user interacts with the UI.
- FloatingActionButton: A round button placed on the screen.
- When clicked, it updates result.value to "FAB clicked".
- shape = RoundedCornerShape(50): Makes it round.
- BottomAppBar: Holds navigation items.
- NavigationBarItem:
- "Favorite" button updates result.value when clicked.
- "Share" button does the same and is selected by default.
- alwaysShowLabel = false: Hides labels when not selected.
Some other useful tutorial
1. Simple Camera App Using CameraX & Jetpack Compose
Build a minimal camera interface with CameraX integration and Compose UI for seamless photo capture.2. Text‑to‑Speech Story App in Jetpack Compose
Learn to convert story text into spoken audio using Android’s TTS API within a Compose‑driven reader.3. Online Shopping App with Jetpack Compose
Create a basic e‑commerce front end featuring product listings, details, and cart UI using Compose.4. Currency Converter App in Jetpack Compose
Implement live currency conversion with Compose, including input fields, dropdowns, and result display.5. Modern Recipe App with Jetpack Compose
Build a beautiful recipe browser with network fetching, caching, and detail screens in Compose.6. MediBihar: Online Medical App in Jetpack Compose
Develop a healthcare interface for browsing doctors, booking appointments, and displaying profiles.7. Freehand Drawing Canvas in Jetpack Compose
Create a touch‑enabled drawing board with color selection, stroke width control, and save functionality.8. Maximizing AdSense & AdMob Earnings in Compose Apps
Integrate Google AdSense and AdMob into your Android app and optimize placements for revenue.9. Analog Clock Widget in Jetpack Compose
Craft a live, animated analog clock component fully in Compose with hour, minute, and second hands.10. Fun Memory‑Match Game in Jetpack Compose
Build a classic card‐matching game with flip animations, score tracking, and level progression.11. 15‑Puzzle Sliding Game in Jetpack Compose
Implement the sliding‑tile “15 puzzle” with smooth animations and move counter using Compose.12. CarWala: Car Shopping App in Jetpack Compose
Design a vehicle marketplace UI showcasing car listings, filters, and detail pages.13. Food Delivery App UI in Jetpack Compose
Create a restaurant menu, cart, and order summary screens for a food ordering interface.14. Tea Shop App with Jetpack Compose
Build a quaint tea‑shop browsing app featuring product listings, images, and “add to cart.”15. Book Store App in Jetpack Compose
Develop a bookstore UI with grid layouts, detail views, and purchase buttons using Compose.16. Simple Dictionary App in Jetpack Compose
Create an offline dictionary with search, word definitions, and history list in Compose.17. Snake Game in Jetpack Compose
Code the classic Snake game with swipe controls, growing snake body, and game‑over logic.18. Pong Game in Jetpack Compose
Recreate the retro Pong arcade game with paddles, ball physics, and scoring in Compose.19. EMI Calculator App in Jetpack Compose
Build a loan EMI calculator with input fields, formula-driven output, and error handling.20. Music Player in Jetpack Compose
Implement a basic audio player UI with play/pause controls, seek bar, and track list.21. Stopwatch App in Jetpack Compose
Create a stopwatch with start/stop, lap timing, and reset functions using Compose.22. Photo Gallery App in Jetpack Compose
Display device photos in a responsive grid, with full‑screen preview and swipe support.23. Jetpack Compose App for Beginners
A hands‑on tutorial covering Compose fundamentals: layouts, state, and basic UI components.24. Text Clock in Android Using Jetpack Compose
Build a digital clock display that updates every second with customizable formats and styles.25. PDF Viewer in Jetpack Compose
Show PDF documents within your app using Compose wrappers around Android’s PDFRenderer.26. Unit Converter App in Jetpack Compose
Develop length, weight, and volume converters with dropdowns and instant result calculations.27. Calculator App in Jetpack Compose
Create a functional arithmetic calculator UI with buttons, input display, and evaluation logic.28. Quiz App Using Jetpack Compose
Build a multiple‑choice quiz interface with question navigation, scoring, and review screens.29. Marquee Text Effect in Jetpack Compose
Implement a smooth scrolling marquee text banner for headlines or announcements.3. BMI Calculator App in Jetpack Compose
Calculate Body Mass Index with user inputs for height and weight, showing health category results.



