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

261
Visualizações
How to detect that a button is pressed in Jetpack Compose?

I try to get a button that has this cool effect of the border radius changing when tapped (like in the Android 12 default calculator application) while also keeping the button's ripple effect.

What I thought would work was this:

var pressed by remember { mutableStateOf(false) }
val borderRadius by animateDpAsState(
    if (pressed) 10.0.dp
    else 20.0.dp
)
val buttonTitle = "uniqueButton"

Button(
    onClick = {
        // some on click stuff
    },
    shape = RoundedCornerShape(borderRadius),
    modifier = Modifier
        .pointerInput(buttonTitle) {
            detectTapGestures(
                onPress = {
                    pressed = true
                    tryAwaitRelease()
                    pressed = false
                }
            )
        }
) {
    Text(text = buttonTitle)
}

But the code within the function passed for onPress is never executed. From my understandig it should be, when the button is tapped or pressed. Where is my mistake, do I misunderstand something in the documentation?

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

0

Most of Compose controls have interactionSource parameter for this purpose. Here's how you can use it:

val interactionSource = remember { MutableInteractionSource() }
val pressed by interactionSource.collectIsPressedAsState()
Button(
    onClick = {},
    interactionSource = interactionSource,
) {

}
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