androidx.compose.material3

Tab

Composable function

A part of PrimaryTabRow. See that page for an overview and examples.

Text and icon

Takes text and icon. Use this one.

@Composable
fun Tab(
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    text: @Composable (() -> Unit)? = null,
    icon: @Composable (() -> Unit)? = null,
    selectedContentColor: Color = LocalContentColor.current,
    unselectedContentColor: Color = selectedContentColor,
    interactionSource: MutableInteractionSource? = null,
)

selected: BooleanRequired

Whether this tab is selected. Usually index == selectedIndex.

onClick: () -> UnitRequired

Called when the tab is clicked. Set your selected index here.

enabled: BooleanOptional

Default: true

Set to false to make the tab gray and not clickable.

text: @Composable (() -> Unit)?Optional

Default: null

The name of the tab. Keep it short.

icon: @Composable (() -> Unit)?Optional

Default: null

An icon above the text, or alone.

Tabs with icons
Tabs with icons
var selected by remember { mutableIntStateOf(0) }
val tabs = listOf("Home" to Icons.Filled.Home, "Favorites" to Icons.Filled.Favorite, "Settings" to Icons.Filled.Settings)
PrimaryTabRow(selectedTabIndex = selected, modifier = Modifier.width(360.dp)) {
    tabs.forEachIndexed { index, (title, icon) ->
        Tab(
            selected = selected == index,
            onClick = { selected = index },
            text = { Text(title) },
            icon = { Icon(icon, contentDescription = null) },
        )
    }
}

selectedContentColor: ColorOptional

Default: LocalContentColor.current

The text and icon color of the selected tab.

unselectedContentColor: ColorOptional

Default: selectedContentColor

The text and icon color of the other tabs.

interactionSource: MutableInteractionSource?Optional

Default: null

Lets you observe or control press, hover and focus states. Leave it null unless your code must react to them. See InteractionSource.

Same as in PrimaryTabRow: modifier.

Custom content

You place the content yourself.

@Composable
fun Tab(
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    selectedContentColor: Color = LocalContentColor.current,
    unselectedContentColor: Color = selectedContentColor,
    interactionSource: MutableInteractionSource? = null,
    content: @Composable ColumnScope.() -> Unit,
)

content: @Composable ColumnScope.() -> UnitRequired

The content of a tab when you don't use text and icon. Items are placed in a Column.

Same as above: selected, onClick, enabled, selectedContentColor, unselectedContentColor, interactionSource.

Same as in PrimaryTabRow: modifier.

Tab types