简体   繁体   English

如何在 Jetpack Compose 中为图标添加阴影/边框/高程

[英]How to add a shadow / border / elevation to an icon in Jetpack Compose

I would like to add a shadow to my icon in Jetpack compose, so that the image & text have a (roughly) similar shadow.我想在 Jetpack compose 中为我的图标添加阴影,以便图像和文本具有(大致)相似的阴影。

来自 https://www.123rf.com/photo_111707392_big-data-vector-icon-isolated-on-transparent-background-big-data-transparency-logo-concept.html 的虚拟图像 在此处输入图像描述

Text(
    text = "HAS SHADOW",
    style = MaterialTheme.typography.body2.copy(
        shadow =  Shadow(
            color = Color(0x4c000000),
            offset = Offset(2f, 2f),
            blurRadius = 7f
        )
    ),
)

Text(
    text = "HAS NO SHADOW",
    style = MaterialTheme.typography.body2
)

Please note: As you can see above, the icon is partly transparent and i want to keep it that way -> solutions like "Wrap it in a FloatingActionButton" won't work请注意:正如您在上面看到的,该图标是部分透明的,我想保持这种方式 -> 像“将它包装在 FloatingActionButton 中”这样的解决方案将不起作用

Can i do this in compose or do i have to ask my designer to add a shadow?我可以在 compose 中执行此操作,还是必须要求我的设计师添加阴影?

For shadow and elevation对于阴影高程

Modifier.shadow(elevation: Dp, shape: Shape, clip: Boolean)

For border用于边框

Modifier.border(border: BorderStroke, shape: Shape)

Also, check the link for other border function variants.此外,请检查其他边框function 变体的链接

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

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