Sermilion
Sermilion

Reputation: 2049

Jetpack Compose Switch Toggle elevation

I have a white Switch on white background. The default switch toggle elevation seems to be to low which results in the toggle blending with the switch and background. I know there is Modifier.shadow that can be applied to modifier, however Switch does not expose the toggle view and its modifier (as far as I figured). So is there a way to control the elevation in such a case? enter image description here

This is what I want to achieve.

enter image description here

Upvotes: 2

Views: 1307

Answers (1)

user496854
user496854

Reputation: 6810

I had the same problem, but there's no easy solution for adding elevation without creating a custom composable. My solution was to change the Switch colors so it doesn't blend into the background. You can do that by modifying the SwitchDefaults.colors, and in the simplest case, you just need to use a different uncheckedThumbColor (in my case, I changed it to a light blue-grey color):

        Switch(
            ...
            colors = SwitchDefaults.colors(
                uncheckedThumbColor = BlueGrey50
            )
            ...
        )

where val BlueGrey50 = Color(0xFFeceff1)

Upvotes: 2

Related Questions