简体   繁体   中英

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.

来自 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

Can i do this in compose or do i have to ask my designer to add a shadow?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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