简体   繁体   中英

How can I change border's color independent of it's width and shape in Jetpack compose?

How can I change composable's border's color, width and shape independently instead of having to pass all 3 properties in one function ie Modifier.border()

I have one simple use case where a 3rd party composable has some kind of border, let's say Red color, 2.dp width and Rectangle shape. Now I only want to change that border's color to Blue but don't mess up with the width and shape, how can I achieve this?

It would be nice to also have Modifer.borderColor() , Modifier.borderWidth() and Modifier.borderShape() extension function along side Modifier.border() . What would be it's implementation and how can I achieve this on my own?

You can create an extension function with default parameters

fun Modifier.border(
    width: Dp = 2.dp,
    color: Color = Color.Red,
    shape: Shape = RectangleShape
) = this.then(Modifier.border(width, color, shape))

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