Change color of Ripple for IconButton in Jetpack compose

2k Views Asked by At

This is not a duplicate of Modify ripple color of IconButton in Jetpack Compose This question was diverted in a different way...

I am trying to change the IconButton ripple colour as follows

IconButton(

        modifier = modifier
            .indication(
                interactionSource = remember { MutableInteractionSource() },
                indication = rememberRipple(
                    bounded = false,
                    radius = 30.dp,
                    color = colorResource(id = R.color.error_red)
                )
            )
            .background(colorResource(id = R.color.white), shape = CircleShape),
        onClick = { onButtonPressed() }
    ) {
        Icon(
            painter = painterResource(R.drawable.ic_busy_small_busy),
            contentDescription = buttonContentDesc,
        )
    }

The ripple colour does not change. It stays dark Grey. Also, Is there a way to change the alpha of the ripple??

1

There are 1 best solutions below

0
JND On

Now you have a colors variable for IconButton:

IconButton(
                    colors = IconButtonDefaults.iconButtonColors(
                        containerColor = colorResource(id = R.color.primary),
                        contentColor = Color.White
                    ),
                    onClick = {
                    // Action
                }) {
                    Icon(Icons.Filled.Edit, contentDescription = null)
                }