Don't understand how to assign text style to Snackbar
Scaffold(
scaffoldState = scaffoldState,
snackbarHost = { hostState ->
SnackbarHost(hostState = hostState) { data ->
Snackbar(
snackbarData = data,
backgroundColor = MaterialTheme.colors.background,
contentColor = MaterialTheme.colors.onBackground,
actionColor = MaterialTheme.colors.primary
)
}
},
scope.launch {
val result = scaffoldState.snackbarHostState.showSnackbar("Removed from favourites","Cancel")
when(result) {
SnackbarResult.ActionPerformed -> {
viewModelForFavourite.addFavouritePhoto(FavouritePhotosEntity(url = photoUrl))
}
else -> Unit
}
}
i found that Snackbar used body2 TextStyle and button TextStyle in file Type.kt but so many actions i used this two, how i can override this in snackBar?
CodePudding user response:
Can we use do as mentioned below
From
SnackbarHost(hostState = hostState) { data ->
Snackbar(
snackbarData = data,
backgroundColor = MaterialTheme.colors.background,
contentColor = MaterialTheme.colors.onBackground,
actionColor = MaterialTheme.colors.primary
)
}
To
SnackbarHost(hostState = hostState) { data ->
Snackbar(
modifier = Modifier.padding(4.dp),
action = {
TextButton(onClick = {}) {
Text(text = data.message)
}
}
) {
Text(text = "This is a basic Snackbar with action item",)
}
}
if yes then we must have control over Text
to make changes as per our requirement
CodePudding user response: