Jetpack Compose - Rounded corners button
Create a rounded corners button in android jetpack compose.
The following code snippet shows how to set rounded corner shapes for Compose Button with 12dp length.
package com.compose.example
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.compose.example.ui.theme.ComposeExampleTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeExampleTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
MainContent()
}
}
}
}
}
@Composable
fun MainContent() {
Box(
contentAlignment = Alignment.Center
) {
// * Rounded corners button
Button(
onClick = { /*TODO*/ }
, shape = RoundedCornerShape(20.dp)
//, shape = RoundedCornerShape(topEnd = 12.dp, bottomEnd = 12.dp)
) {
Text(
text = "Rounded corners button",
Modifier.padding(12.dp))
}
}
}
..
Comments
Post a Comment