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
selected: BooleanRequiredWhether this tab is selected. Usually index == selectedIndex.
onClick: () -> UnitRequired
onClick: () -> UnitRequiredCalled when the tab is clicked. Set your selected index here.
enabled: BooleanOptional
enabled: BooleanOptionalDefault: true
Set to false to make the tab gray and not clickable.
text: @Composable (() -> Unit)?Optional
text: @Composable (() -> Unit)?OptionalDefault: null
The name of the tab. Keep it short.
icon: @Composable (() -> Unit)?Optional
icon: @Composable (() -> Unit)?OptionalDefault: null
An icon above the text, or alone.

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
selectedContentColor: ColorOptionalDefault: LocalContentColor.current
The text and icon color of the selected tab.
unselectedContentColor: ColorOptional
unselectedContentColor: ColorOptionalDefault: selectedContentColor
The text and icon color of the other tabs.
interactionSource: MutableInteractionSource?Optional
interactionSource: MutableInteractionSource?OptionalDefault: 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
content: @Composable ColumnScope.() -> UnitRequiredThe 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.