How to create rounded border Button using Jetpack Compose
19,107
Solution 1
With 1.0.x
to achieve a button with a border with rounded corners you can use the OutlinedButton
component applying in the shape
parameter a RoundedCornerShape
:
OutlinedButton(
onClick = { },
border = BorderStroke(1.dp, Color.Red),
shape = RoundedCornerShape(50), // = 50% percent
//or shape = CircleShape
colors = ButtonDefaults.outlinedButtonColors(contentColor = Color.Red)
){
Text( text = "Save" )
}
Solution 2
Just use modifier as:
modifier = Modifier.border( width = 2.dp,
color = Color.Red,
shape = RoundedCornerShape(5.dp))
Solution 3
Use the clip
Modifier.
Modifier.clip(CircleShape)
Solution 4
use Clip Modifier, plus you can also choose a specific corner to curve
modifier = Modifier.clip(RoundedCornerShape(15.dp, 15.dp, 0.dp, 0.dp))
![Sanjayrajsinh](https://i.stack.imgur.com/r6bVp.jpg?s=256&g=1)
Author by
Sanjayrajsinh
Updated on June 19, 2022Comments
-
Sanjayrajsinh about 2 years
-
Sanjayrajsinh over 4 yearsThank you sir , but i want with custom ui with rounded border
-
Gabriele Mariotti over 4 years@Sanjayrajsinh the
OutlinedButtonStyle
has rounded corners by default. You can in any case override the value usingshape = RoundedCornerShape(x.dp)
-
Gabriele Mariotti over 4 years@Sanjayrajsinh or using a percent value with
shape = RoundedCornerShape(50)
. I've just updated the answer. -
Ranjithkumar almost 3 years@GabrieleMariotti I don't see any difference between Button() and OutlinedButton(). If I use the same code with Button() it will give same result. May I know what's the difference ?
-
Gabriele Mariotti almost 3 years@RanjithKumar The
OutlinedButton
is aButton
with anoutlinedBorder
and custom colors asbackgroundColor= MaterialTheme.colors.surface
andcontentColor = MaterialTheme.colors.primary
-
Ranjithkumar almost 3 years@GabrieleMariotti thank you so much. You are my guru.