MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
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 - Box vs Surface",
color = Color.White)},
backgroundColor = Color(0xFF333399)) },
content = { Box(Modifier.fillMaxSize()
.background(Color(0XFFEDEAE0))){MainContent()}}
)
}
@Composable
fun MainContent(){
Column(
Modifier.padding(32.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
){
Box(
Modifier
.fillMaxWidth().height(150.dp)
.background( color = Color(0xFF87A96B) ),
contentAlignment = Alignment.Center,
){ Text("Box") }
Surface(
Modifier.fillMaxWidth().height(150.dp),
color = Color(0xFF87A96B),
border = BorderStroke(2.dp,Color.Red),
elevation = 4.dp
) {
Text("Surface")
}
}
}
@Preview
@Composable
fun ComposablePreview(){
//GetScaffold()
}
}
- jetpack compose - Outlined Button
- jetpack compose - Button elevation
- jetpack compose - TextField request focus
- jetpack compose - TextField size
- jetpack compose - TextField error
- jetpack compose - TextField IME action done
- jetpack compose - Card click
- jetpack compose - Show toast message
- jetpack compose - Get context
- jetpack compose - Box alignment
- jetpack compose - Box elevation
- jetpack compose - Column center
- jetpack compose - Column background color
- jetpack compose - Row spacing
- jetpack compose - Row scrolling