Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

865
Visualizações
Jetpack Compose, how to change the color of the action of the snackbar in .showSnackbar() in a Scaffold?

So, I'm showing a snackbar inside of my Scaffold, using the scaffoldState.snackbarHostState.showSnackbar() method, though the colour of the "Undo" action is dark purple, and I would like to change it to something else.

I know that I can show it as a custom component, though I would like to launch it in a coroutineScope(), which I think is not possible.

My code is like this for the snackbar.

scope.launch {
  val result = scaffoldState.snackbarHostState.showSnackbar(
    message = "Note Deleted",
    actionLabel = "Undo",
  )
  if (result == SnackbarResult.ActionPerformed) { 
    viewModel.onEvent(NotesEvent.RestoreNote)
  }
}

I would like to know if it's possible to change the text colour of the action here and if yes, it would be cool if you could give an example or a resource.

Thanks!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can customize your Snackbar using the actionColor parameter.

Something like:

val scaffoldState = rememberScaffoldState()
Scaffold(
    scaffoldState = scaffoldState,
    snackbarHost = {
        // reuse default SnackbarHost to have default animation and timing handling
        SnackbarHost(it) { data ->
            // custom snackbar with the custom colors
            Snackbar(
                actionColor = Green,
                //contentColor = ...,
                snackbarData = data
            )
        }
    },

Then just use it:

scope.launch {
        scaffoldState.snackbarHostState.showSnackbar(
               message = "Note Deleted",
               actionLabel = "Undo"
         )
}

enter image description here

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda