简体   繁体   English

Jetpack Compose 开关切换高度

[英]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).我知道有Modifier.shadow可以应用于修改器,但是 Switch 不会公开切换视图及其修改器(据我所知)。 So is there a way to control the elevation in such a case?那么在这种情况下有没有办法控制海拔呢? 在此处输入图像描述

This is what I want to achieve.这就是我想要实现的。

在此处输入图像描述

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.我的解决方案是更改 Switch colors,使其不会融入背景。 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):您可以通过修改SwitchDefaults.colors来做到这一点,在最简单的情况下,您只需要使用不同的uncheckedThumbColor (在我的例子中,我将其更改为浅蓝灰色):

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

where val BlueGrey50 = Color(0xFFeceff1)其中val BlueGrey50 = Color(0xFFeceff1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM