Building on the tutorial referenced in the above answer, I created an extension function to the DialogWindowScope
and added it as the first element in an undecorated Dialog
Dialog(...) {
Column (...) {
dialogTitleBar("dialog title") { on close clicked }
}
}
@Composable
fun DialogWindowScope.dialogTitleBar(
title: String? = null,
onClick: () -> Unit
) = WindowDraggableArea{
Column(modifier = Modifier.fillMaxWidth()) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier.padding(start = 10.dp, bottom = 4.dp, top = 4.dp),
color = MaterialTheme.colors.primary,
fontSize = MaterialTheme.typography.body2.fontSize,
text = title ?: ""
)
CloseButton(onClick)
}
Divider(
Modifier.fillMaxWidth(),
color = MaterialTheme.colors.primary.copy(alpha = .95f)
)
}
}
@Composable
fun CloseButton(onClick: () -> Unit) {
val interactionSource = remember { MutableInteractionSource() }
val isHovered by interactionSource.collectIsHoveredAsState()
Icon(
modifier = Modifier.size(24.dp)
.background(if (isHovered) Color.Red else MaterialTheme.colors.onPrimary)
.hoverable(interactionSource)
.clickable(onClick = onClick),
imageVector = Icons.Default.Close,
contentDescription = "Close",
tint = MaterialTheme.colors.primary
)
}```