Compose Unstyled 2.0 is out! Check the official announcement blog ->

Medium, centered, and large title toolbars for page-level actions and navigation.

Use toolbars to anchor a screen title, navigation affordances, and top-level actions.

View on GitHub
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.composables.icons.lucide.ArrowLeft
import com.composables.icons.lucide.EllipsisVertical
import com.composables.icons.lucide.Lucide
import com.composables.icons.lucide.Share
import com.composables.ui.components.ButtonStyle
import com.composables.ui.components.Icon
import com.composables.ui.components.IconButton
import com.composables.ui.components.Text
import com.composables.ui.components.Toolbar

@Composable
fun ToolbarWithActionsExample() {
    Toolbar(
        modifier = Modifier.fillMaxWidth(),
        title = { Text("Title") },
        leading = {
            IconButton(
                onClick = { /* TODO */ },
                style = ButtonStyle.Ghost,
            ) {
                Icon(Lucide.ArrowLeft, contentDescription = "Go back")
            }
        },
        trailing = {
            IconButton(
                onClick = { /* TODO */ },
                style = ButtonStyle.Ghost,
            ) {
                Icon(
                    imageVector = Lucide.Share,
                    contentDescription = "Share",
                    modifier = Modifier.size(18.dp),
                )
            }
            IconButton(
                onClick = { /* TODO */ },
                style = ButtonStyle.Ghost,
            ) {
                Icon(
                    imageVector = Lucide.EllipsisVertical,
                    contentDescription = "More options",
                    modifier = Modifier.size(18.dp),
                )
            }
        },
    )
}

Installation

implementation("com.composables:ui:0.1.0")

Examples

Centered

View on GitHub
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.composables.icons.lucide.ArrowLeft
import com.composables.icons.lucide.EllipsisVertical
import com.composables.icons.lucide.Lucide
import com.composables.ui.components.ButtonStyle
import com.composables.ui.components.Icon
import com.composables.ui.components.IconButton
import com.composables.ui.components.Text
import com.composables.ui.components.CenteredToolbar

@Composable
fun CenteredToolbarExample() {
    CenteredToolbar(
        modifier = Modifier.fillMaxWidth(),
        leading = {
            IconButton(
                onClick = { /* TODO */ },
                style = ButtonStyle.Ghost,
            ) {
                Icon(Lucide.ArrowLeft, contentDescription = "Go back")
            }
        },
        title = { Text("Centered") },
        trailing = {
            IconButton(
                onClick = { /* TODO */ },
                style = ButtonStyle.Ghost,
            ) {
                Icon(
                    imageVector = Lucide.EllipsisVertical,
                    contentDescription = "More options",
                    modifier = Modifier.size(18.dp),
                )
            }
        },
    )
}

Large

View on GitHub
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.composables.icons.lucide.EllipsisVertical
import com.composables.icons.lucide.Lucide
import com.composables.ui.components.ButtonStyle
import com.composables.ui.components.Icon
import com.composables.ui.components.IconButton
import com.composables.ui.components.Text
import com.composables.ui.components.Toolbar
import com.composables.ui.components.ToolbarSize

@Composable
fun LargeToolbarExample() {
    Toolbar(
        modifier = Modifier.fillMaxWidth(),
        title = { Text("Large title") },
        size = ToolbarSize.Large,
        trailing = {
            IconButton(
                onClick = { /* TODO */ },
                style = ButtonStyle.Ghost,
            ) {
                Icon(
                    imageVector = Lucide.EllipsisVertical,
                    contentDescription = "More options",
                    modifier = Modifier.size(18.dp),
                )
            }
        },
    )
}

API Reference

Toolbar

A top app bar with medium and large title variants.

@Composable
fun Toolbar(
    title: @Composable RowScope.() -> Unit,
    modifier: Modifier = Modifier,
    backgroundColor: Color = Color.Transparent,
    contentColor: Color = LocalContentColor.current,
    windowInsets: WindowInsets = toolbarWindowInsets(),
    leading: @Composable (RowScope.() -> Unit)? = null,
    trailing: @Composable (RowScope.() -> Unit)? = null,
    size: ToolbarSize = ToolbarSize.Medium,
)
Parameter Type Description
title @Composable RowScope.() -> Unit Composable title content displayed by the toolbar.
modifier Modifier Modifier applied to the toolbar.
backgroundColor Color Background color used by the toolbar.
contentColor Color Color used for toolbar content.
windowInsets WindowInsets Insets applied around the toolbar content.
leading @Composable (RowScope.() -> Unit)? Optional leading content shown before the title.
trailing @Composable (RowScope.() -> Unit)? Optional trailing content shown after the title.
size ToolbarSize Size variant used by the standard toolbar.

CenteredToolbar

A toolbar with centered title content.

@Composable
fun CenteredToolbar(
    title: @Composable (RowScope.() -> Unit),
    modifier: Modifier = Modifier,
    leading: @Composable (RowScope.() -> Unit)? = null,
    trailing: @Composable (RowScope.() -> Unit)? = null,
    backgroundColor: Color = Color.Transparent,
    contentColor: Color = LocalContentColor.current,
    windowInsets: WindowInsets = toolbarWindowInsets(),
)
Parameter Type Description
title @Composable (RowScope.() -> Unit) Composable title content displayed by the toolbar.
modifier Modifier Modifier applied to the toolbar.
leading @Composable (RowScope.() -> Unit)? Optional leading content shown before the title.
trailing @Composable (RowScope.() -> Unit)? Optional trailing content shown after the title.
backgroundColor Color Background color used by the toolbar.
contentColor Color Color used for toolbar content.
windowInsets WindowInsets Insets applied around the toolbar content.

ToolbarSize

Size variants for the standard Toolbar.

@JvmInline
value class ToolbarSize internal constructor(@Suppress("unused") private val value: Int)
Value Description
Medium Uses the standard single-row toolbar height.
Large Uses the large title toolbar layout.