How to add border to card view with jetpack compose

44k views Asked by At

I find the way Border(1.dp, Color.Black) can not work with the border property of Card view, what's the best way to work around of it?

2

There are 2 answers

0
Gabriele Mariotti On

You can use the border parameter to specify a BorderStroke to draw the border on top of the card:

Card(
        border = BorderStroke(2.dp,Color.Red),
        backgroundColor = Color.Yellow){

}

enter image description here

With Material3 you can use:

Card(
        border = BorderStroke(2.dp,Color.Red),
        colors = CardDefaults.cardColors(containerColor = Yellow)
)
2
ccd On

The border api of Card change to subtitle of Modifier, so it can add a border under below.

Card(modifier = Modifier.border(1.dp, Color.Black)) {...}