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.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
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 {
MainContent()
}
}
@Composable
fun MainContent(){
Box(
Modifier
.fillMaxSize()
.padding(16.dp)
) {
Button(onClick = {
// do something
},
modifier = Modifier.align(Alignment.TopCenter)
) {
Text(text = "Top Center" )
}
Button(onClick = { },
colors = ButtonDefaults.textButtonColors(
backgroundColor = Color(0xFF9FA91F),
contentColor = Color(0xFFFFF8DC)
),
modifier = Modifier.align(Alignment.BottomStart)
) {
Text(text = "Bottom Start" )
}
Button(onClick = { },
colors = ButtonDefaults.textButtonColors(
backgroundColor = Color(0xFFC32148),
contentColor = Color(0xFFFFFF99)
),
modifier = Modifier.align(Alignment.BottomEnd)
) {
Text(text = "Bottom End" )
}
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - Radio group example
- jetpack compose - How to use Floating Action Button
- jetpack compose - Extended floating action button example
- jetpack compose - How to use DropdownMenu
- jetpack compose - How to use IconButton
- jetpack compose - How to use IconToggleButton
- jetpack compose - How to use Column layout
- jetpack compose - How to use Row layout
- jetpack compose - How to use AlertDialog
- jetpack compose - Image size
- jetpack compose - Image shape
- jetpack compose - Image tint
- jetpack compose - Image scale
- jetpack compose - Image background
- jetpack compose - Image from URL