ListHeader

Functions summary

Unit
@Composable
ListHeader(
    modifier: Modifier,
    backgroundColor: Color,
    contentColor: Color,
    contentPadding: PaddingValues,
    transformation: SurfaceTransformation?,
    content: @Composable RowScope.() -> Unit
)

A slot based composable for creating a list header item.

Functions

@Composable
fun ListHeader(
    modifier: Modifier = Modifier,
    backgroundColor: Color = Color.Transparent,
    contentColor: Color = ListHeaderDefaults.contentColor,
    contentPadding: PaddingValues = ListHeaderDefaults.ContentPadding,
    transformation: SurfaceTransformation? = null,
    content: @Composable RowScope.() -> Unit
): Unit

A slot based composable for creating a list header item. ListHeaders are typically expected to be a few words of text on a single line. The contents will be start and end padded.

ListHeader scales itself appropriately when used within the scope of a TransformingLazyColumn.

Example of a ListHeader:

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.ButtonDefaults
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.ListHeader
import androidx.wear.compose.material3.ListSubHeader
import androidx.wear.compose.material3.ScreenScaffold
import androidx.wear.compose.material3.Text

val scrollState = rememberScalingLazyListState()

ScreenScaffold(scrollState = scrollState, modifier = Modifier.background(Color.Black)) {
    contentPadding ->
    ScalingLazyColumn(
        state = scrollState,
        modifier = Modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally,
        contentPadding = contentPadding,
    ) {
        item { ListHeader { Text("Settings") } }
        item {
            ListSubHeader(
                icon = {
                    Icon(
                        painter = painterResource(R.drawable.ic_connectivity),
                        contentDescription = "Connectivity",
                    )
                },
                label = { Text("Connectivity") },
            )
        }
        item {
            Button(
                modifier = Modifier.fillMaxWidth(),
                onClick = {},
                icon = {
                    Icon(
                        painter = painterResource(R.drawable.ic_bluetooth),
                        contentDescription = "Bluetooth",
                        modifier = Modifier.size(ButtonDefaults.IconSize),
                    )
                },
            ) {
                Text("Bluetooth")
            }
        }
        item {
            Button(
                modifier = Modifier.fillMaxWidth(),
                onClick = {},
                icon = {
                    Icon(
                        painter = painterResource(R.drawable.ic_wifi),
                        contentDescription = "Wifi",
                        modifier = Modifier.size(ButtonDefaults.IconSize),
                    )
                },
            ) {
                Text("Wifi")
            }
        }
        item { ListSubHeader { Text("Display") } }
        item {
            Button(modifier = Modifier.fillMaxWidth(), onClick = {}) {
                Text("Change Watchface")
            }
        }
        item { Button(modifier = Modifier.fillMaxWidth(), onClick = {}) { Text("Brightness") } }
    }
}
Parameters
modifier: Modifier = Modifier

The modifier for the ListHeader.

backgroundColor: Color = Color.Transparent

The background color to apply - typically Color.Transparent

contentColor: Color = ListHeaderDefaults.contentColor

The color to apply to content.

contentPadding: PaddingValues = ListHeaderDefaults.ContentPadding

The spacing values to apply internally between the background and the content.

transformation: SurfaceTransformation? = null

Transformation to be used when header appears inside the container that needs to dynamically change its content separately from the background.

content: @Composable RowScope.() -> Unit

Slot for ListHeader content, expected to be a single line of text.