Jetpack Compose Question: I am trying to get a and...
# compose
g
Jetpack Compose Question: I am trying to get a android.ui.material.button to look pressed. How is that done in compose?
a
Is it not pressed when you touch it?
g
It doesn’t show a ripple effect visually
I click happens but the button doesn’t visually show the press
l
Could you share some code?
s
Make sure you provide a callback to be called when it's pressed. Otherwise, it'll be disabled.
1
a
@sindrenm fwiw we're going to be adding explicit
enabled: Boolean
params to these composables and not using nullable callbacks as that signal. It's often confusing and leads to very strange code shapes the way it is today.
🎉 1
👍 1
g
I have an onClick callback but still get no visual indication. Is there something else I need to do?
a
can you show the code? maybe the Ripple is drawn with the same color as the background, for example
👍 1
g
Copy code
@Composable
fun ButtonStyled (text : String, onClick:  (() -> Unit)?) {
    Button(onClick = onClick) {
        Text(text)
    }
}
Copy code
Column() {
    ButtonStyled(
        text = "Refresh",
        onClick = { bleTestViewModel.devicesRefresh() }
    )
}
l
Are you setting a theme anywhere? (
MaterialTheme
)
g
Yes.
Copy code
private fun SwitchPage (newPage : AppPages ) {
    currentPage = newPage
    setContent {
        MaterialTheme {
            when (currentPage) {
                AppPages.DEVICES_PAGE -> {
                    DevicesPage()
                }
                AppPages.DEVICE_PAGE -> {
                    DevicePage()
                }
                AppPages.UART_PAGE -> {
                    UARTPage()
                }
                <http://AppPages.INFO|AppPages.INFO>_PAGE -> {
                    InfoPage()
                }
                AppPages.NO_PAGE -> {
                }
            }
        }
    }
}
It works it is just very subtle. I changed the color of the button and it shows a bit more.