Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a shadow color for Jetpack Compose?

Sorry, I can hardly speak English.

machine translation:

How do I set a shadow color for Jetpack Compose?

I can set shadows, but they're ugly.

Jetpack Compose code:

Surface(
    modifier = Modifier.width(160.dp).height(56.dp),
    shape = CircleShape,
    elevation = 2.dp,
) {
    ...
}

I want to create a shadow in the code below.

SwiftUI code:

ZStack {
    ...
}
.shadow(color: Color("button_shadow"), radius: 4, x: 0, y: 2)
.shadow(color: Color("button_shadow"), radius: 20, x: 0, y: 4)

Dark mode also requires a white shadow.

enter image description here

enter image description here

You want to be able to customize the color of the shadow.

like image 736
郭大鹏 Avatar asked Feb 15 '21 06:02

郭大鹏


1 Answers

In my case for cycle I use this workaround:

@Composable
fun MyButton(){
    Box(
        modifier = Modifier
            .size(64.dp)
            .background(
                brush = Brush.radialGradient(
                    colors = listOf(
                        Color.Yellow,
                        Color.Transparent
                    )
                )
            )
            .padding(bottom = 4.dp),
        contentAlignment = Alignment.Center
    ) {
        Surface(
            shape = CircleShape,
            modifier = Modifier
                .size(55.dp)
                .background(Color.Transparent)
                .clickable { }
        ) {
            Box(
                modifier = Modifier.padding()
                    .background(Color.Gray),
                contentAlignment = Alignment.Center
            ) {
                Icon(
                    modifier = Modifier.size(35.dp),
                    imageVector = Icons.Filled.Refresh,
                    contentDescription = "",
                    tint =  Color.Yellow
                )
            }
        }

    }
}

there is the preview:

enter image description here

like image 184
Evgenii Doikov Avatar answered Oct 07 '22 18:10

Evgenii Doikov