MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
GetScaffold()
}
}
@Composable
fun GetScaffold(){
Scaffold(
topBar = {TopAppBar(
title = {Text(
"Compose - Card Corner Radius",
color = Color.White)},
backgroundColor = Color(0xFF58427C)) },
content = {MainContent()},
backgroundColor = Color(0xFFEDEAE0)
)
}
@Composable
fun MainContent(){
Column(
modifier = Modifier
.fillMaxSize()
.padding(12.dp),
verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.CenterHorizontally
) {
Card(
modifier = Modifier
.fillMaxWidth()
.height(150.dp),
backgroundColor = Color(0xFFE97451),
elevation = 4.dp,
shape = RoundedCornerShape(12.dp),
) {
Box(Modifier.wrapContentSize(Alignment.Center)){
Text(
text = "Card Corner Radius 12 DP",
style = MaterialTheme.typography.h6
)
}
}
Card(
modifier = Modifier
.fillMaxWidth()
.height(150.dp),
backgroundColor = Color(0xFF1F75FE),
elevation = 4.dp,
shape = RoundedCornerShape(topEnd = 20.dp),
) {
Box(Modifier.wrapContentSize(Alignment.Center)){
Text(
text = "Top End Only 20 DP",
style = MaterialTheme.typography.h6
)
}
}
Card(
modifier = Modifier.size(200.dp),
backgroundColor = Color(0xFFFFAA1D),
elevation = 4.dp,
shape = CircleShape,
) {
Box(Modifier.wrapContentSize(Alignment.Center)){
Text(
text = "Circular Card",
style = MaterialTheme.typography.h6
)
}
}
}
}
@Preview
@Composable
fun ComposablePreview(){
//GetScaffold()
}
}
- jetpack compose - Box gravity
- jetpack compose - Card center
- jetpack compose - Card shadow
- jetpack compose - Card border
- jetpack compose - Navigation multiple arguments
- jetpack compose - Navigation arguments data type
- jetpack compose - Navigation object argument
- jetpack compose - Double click listener
- jetpack compose - Long click listener
- jetpack compose - Pass onClick event to function
- jetpack compose - How to change StatusBar color
- jetpack compose - How to change NavigationBar color
- jetpack compose - How to change SystemBars color
- jetpack compose - Kotlinx serialization not encode null values
- jetpack compose - Kotlinx serialization encode to string