Re-usable custom toolbar jetpack composed
@Composable fun CustomToolbarScreen(navController: NavHostController, title: String, isBack: Boolean){
val scaffoldState = rememberScaffoldState()
val scope = rememberCoroutineScope()
var isDrawerOpen = remember {
mutableStateOf(false)
}
TopAppBar(
colors = TopAppBarDefaults.smallTopAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary,
),
title = {
Text(text = title,color = Color.Black,
fontSize = 18.sp)
},
modifier = Modifier.background(colorPrimary),
navigationIcon = {
if (isBack){
IconButton(onClick = {navController.navigateUp()}) {
Icon(Icons.Filled.ArrowBack, "backIcon")
}
}else{
IconButton(onClick = {
scope.launch {
scaffoldState.drawerState.open()
Log.i("Drawer", "drawer Open: ")
}
}) {
Icon(Icons.Filled.Menu, "backIcon")
}
}
}
)}
More details please visit this link
custom toolbar