https://kotlinlang.org logo
g

Guy Bieber

03/10/2020, 1:41 PM
Jetpack Compose Question: I am trying to get a android.ui.material.button to look pressed. How is that done in compose?
a

Adam Powell

03/10/2020, 1:51 PM
Is it not pressed when you touch it?
g

Guy Bieber

03/10/2020, 2:55 PM
It doesn’t show a ripple effect visually
I click happens but the button doesn’t visually show the press
l

Louis Pullen-Freilich [G]

03/10/2020, 3:13 PM
Could you share some code?
s

sindrenm

03/10/2020, 3:49 PM
Make sure you provide a callback to be called when it's pressed. Otherwise, it'll be disabled.
1
a

Adam Powell

03/10/2020, 11:47 PM
@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

Guy Bieber

03/11/2020, 8:16 PM
I have an onClick callback but still get no visual indication. Is there something else I need to do?
a

Andrey Kulikov

03/11/2020, 9:24 PM
can you show the code? maybe the Ripple is drawn with the same color as the background, for example
👍 1
g

Guy Bieber

03/11/2020, 11:24 PM
Copy code
@Composable
fun ButtonStyled (text : String, onClick:  (() -> Unit)?) {
    Button(onClick = onClick) {
        Text(text)
    }
}
Copy code
Column() {
    ButtonStyled(
        text = "Refresh",
        onClick = { bleTestViewModel.devicesRefresh() }
    )
}
l

Louis Pullen-Freilich [G]

03/12/2020, 12:02 AM
Are you setting a theme anywhere? (
MaterialTheme
)
g

Guy Bieber

03/12/2020, 12:21 AM
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.