MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
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.Brush
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 Background Color",
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(175.dp),
backgroundColor = Color(0xFFFFBCD9),
elevation = 4.dp,
shape = RoundedCornerShape(24.dp),
) {
Box(Modifier.padding(16.dp)) {
Text(
text = "Card Solid Background",
style = MaterialTheme.typography.h6
)
}
}
Card(
modifier = Modifier
.fillMaxWidth()
.height(175.dp),
backgroundColor= Color.Transparent,
elevation = 4.dp,
shape = RoundedCornerShape(24.dp),
) {
Box(
Modifier
.background(
Brush.radialGradient(
listOf(
Color(0XFFFAD6A5),
Color(0XFFFF5470),
Color(0XFF7DF9FF)
)
)
)
.padding(12.dp)
) {
Text(
text = "Card Gradient Background",
style = MaterialTheme.typography.h6
)
}
}
}
}
@Preview
@Composable
fun ComposablePreview(){
//GetScaffold()
}
}
- jetpack compose - Card padding
- jetpack compose - Card alignment
- jetpack compose - Card clickable
- jetpack compose - ModalDrawer example
- jetpack compose - Update state of another function variable
- jetpack compose - TopAppBar navigation
- jetpack compose - TopAppBar actions
- jetpack compose - Scaffold with Drawer
- jetpack compose - Open close drawer in code
- jetpack compose - Scaffold with Snackbar
- jetpack compose - Dismiss Snackbar programmatically
- jetpack compose - Snackbar host state
- jetpack compose - Scaffold Snackbar host
- jetpack compose - AndroidView modifier
- jetpack compose - How to use bottom navigation