Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Created December 12, 2022 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KatieBarnett/31b2f0ecee4861e4126b7dabeee9ed97 to your computer and use it in GitHub Desktop.
Save KatieBarnett/31b2f0ecee4861e4126b7dabeee9ed97 to your computer and use it in GitHub Desktop.
Changing colour fixed TopAppBar
...
val listState = rememberLazyListState()
val isScrolled = remember { derivedStateOf { listState.firstVisibleItemIndex > 0 } }
val topAppBarContainerColor = if (isScrolled.value) {
MaterialTheme.colorScheme.surfaceVariant
} else {
MaterialTheme.colorScheme.surface
}
Scaffold(
topBar = {
TopAppBar(
title = { Text(text = stringResource(id = R.string.title)) },
navigationIcon = { NavigationIcon(navController = navController)},
actions = { AboutActionIcon(navController) },
colors = TopAppBarDefaults.smallTopAppBarColors(
containerColor = topAppBarContainerColor,
navigationIconContentColor = MaterialTheme.colorScheme.onSurface,
actionIconContentColor = MaterialTheme.colorScheme.onSurface,
titleContentColor = MaterialTheme.colorScheme.onSurface
)
)
},
modifier = modifier
) { innerPadding ->
LazyColumn(
state = listState,
modifier = Modifier.fillMaxSize().padding(innerPadding)) {
items(items) { item ->
...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment