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.draw.clip
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 - Column Weight",
color = Color.White)},
backgroundColor = Color(0xFF58427C)) },
content = {MainContent()},
backgroundColor = Color(0xFFEDEAE0)
)
}
@Composable
fun MainContent(){
Column(
modifier = Modifier
.background(Color(0xFF960018))
.fillMaxSize()
.padding(12.dp),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxSize()
.weight(3f)
.clip(RoundedCornerShape(12.dp))
.background(Color(0xFF89CFF0))
){
Text(
text = "Weight 3F",
style = MaterialTheme.typography.h5
)
}
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxSize()
.weight(5f)
.clip(RoundedCornerShape(12.dp))
.background(Color(0xFFACE5EE))
){
Text(
text = "Weight 5F",
style = MaterialTheme.typography.h5
)
}
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxSize()
.weight(2f)
.clip(RoundedCornerShape(12.dp))
.background(Color(0xFFA1CAF1))
){
Text(
text = "Weight 2F",
style = MaterialTheme.typography.h5
)
}
}
}
@Preview
@Composable
fun ComposablePreview(){
//GetScaffold()
}
}
- jetpack compose - Row onClick
- jetpack compose - Row weight
- jetpack compose - Row center vertically
- jetpack compose - Row align end
- jetpack compose - Update state of another function variable
- jetpack compose - TopAppBar navigation
- jetpack compose - TopAppBar actions
- jetpack compose - TopAppBar center title
- jetpack compose - TopAppBar menu
- jetpack compose - Scaffold with Drawer
- jetpack compose - Open close drawer in code
- jetpack compose - Scaffold with Snackbar
- jetpack compose - Snackbar action
- jetpack compose - Snackbar dismiss listener
- jetpack compose - Dismiss Snackbar programmatically