The role of a button is significant while developing Android apps. Let’s learn how to add a button with Rounded corners in Jetpack Compose.
As you know, changing the border radius makes the corners of a button round. Here, you can use Shape to make the corners round. See the code snippet given below.
Button(onClick = { /*TODO*/ },
shape = RoundedCornerShape(20.dp)) {
Text("Button with Rounded Corners")
}
This gives a border radius of 20 dp to all corners of the button. Following is the complete Android Jetpack Compose button with rounded corners example.
package com.example.example
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.example.ui.theme.ExampleTheme
import com.example.example.ui.theme.Shapes
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ExampleTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
buttonExample()
}
}
}
}
}
@Composable
fun buttonExample() {
Box() {
Button(onClick = { /*TODO*/ },
shape = RoundedCornerShape(20.dp),
modifier = Modifier.align(Alignment.Center)) {
Text("Button with Rounded Corners")
}
}
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
ExampleTheme {
buttonExample()
}
}
Following is the output of the above example.

I hope this Jetpack Compose tutorial is helpful for you.