Thread
#compose
    g

    Guy Bieber

    2 years ago
    Jetpack Compose Question: I am trying to get a android.ui.material.button to look pressed. How is that done in compose?
    Adam Powell

    Adam Powell

    2 years ago
    Is it not pressed when you touch it?
    g

    Guy Bieber

    2 years ago
    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]

    2 years ago
    Could you share some code?
    sindrenm

    sindrenm

    2 years ago
    Make sure you provide a callback to be called when it's pressed. Otherwise, it'll be disabled.
    Adam Powell

    Adam Powell

    2 years ago
    @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.
    g

    Guy Bieber

    2 years ago
    I have an onClick callback but still get no visual indication. Is there something else I need to do?
    Andrey Kulikov

    Andrey Kulikov

    2 years ago
    can you show the code? maybe the Ripple is drawn with the same color as the background, for example
    g

    Guy Bieber

    2 years ago
    @Composable
    fun ButtonStyled (text : String, onClick:  (() -> Unit)?) {
        Button(onClick = onClick) {
            Text(text)
        }
    }
    Column() {
        ButtonStyled(
            text = "Refresh",
            onClick = { bleTestViewModel.devicesRefresh() }
        )
    }
    l

    Louis Pullen-Freilich [G]

    2 years ago
    Are you setting a theme anywhere? (
    MaterialTheme
    )
    g

    Guy Bieber

    2 years ago
    Yes.
    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.