To add a menu 'IconButton' to your 'TopAppBar' while using your existing 'Drawer' function, you can wrap the existing 'Drawer' function within a 'Scaffold' composable - you can follow a full tutorial at -
Jetpack Compose: What’s a Scaffold?[
^]
You can adjust teh code I used below to suit your need as you did not give a lot of information -
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DrawerContent() {
val items = listOf(
DrawerItem(
Icons.Default.Favorite,
"Favourite"
),
DrawerItem(
Icons.Default.Add,
"Add"
),
DrawerItem(
Icons.Default.AccountBox,
"Account"
)
)
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
val scope = rememberCoroutineScope()
val selectedItem = remember { mutableStateOf(items[0]) }
ModalDrawer(
drawerState = drawerState,
drawerContent = {
ModalDrawerSheet {
Image(
painter = painterResource(id = R.drawable.globologo),
contentDescription = "Header Image",
modifier = Modifier
.fillMaxWidth()
.height(150.dp)
.padding(all = 10.dp),
contentScale = ContentScale.Inside
)
Spacer(modifier = Modifier.height(10.dp))
items.forEach { item ->
NavigationDrawerItem(
label = {
Text(text = item.title)
},
selected = selectedItem.value == item,
icon = {
Icon(
imageVector = item.imageVector,
contentDescription = item.title
)
},
onClick = {
scope.launch {
selectedItem.value = item
drawerState.close()
}
}
)
}
}
},
content = {
TopAppBar(
title = { Text(text = "App Title") },
navigationIcon = {
IconButton(onClick = {
scope.launch {
drawerState.open()
}
}) {
Image(
painter = painterResource(id = R.drawable.hamburgermenu),
contentDescription = "Menu",
modifier = Modifier.size(24.dp)
)
}
}
) {
}
}
)
}
@Composable
fun NavigationDrawerItem(
label: @Composable () -> Unit,
selected: Boolean,
icon: @Composable () -> Unit,
onClick: () -> Unit
) {
}
@Composable
fun DrawerItem(imageVector: ImageVector, title: String) {
}