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.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(){
Row(
Modifier
.background(Color(0xFFEDEAE0))
.padding(16.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceEvenly
) {
Button(onClick = {
// do something
}
) {
Text(text = "First" )
}
Button(onClick = { },
colors = ButtonDefaults.textButtonColors(
backgroundColor = Color(0xFF333399),
contentColor = Color(0xFFF0FFFF)
)
) {
Text(text = "Second" )
}
Button(onClick = { },
colors = ButtonDefaults.textButtonColors(
backgroundColor = Color(0xFFC32148),
contentColor = Color(0xFFFFFF99)
)
) {
Text(text = "Third" )
}
}
}
@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 - Box layout example
- jetpack compose - How to use AlertDialog
- jetpack compose - Indeterminate CircularProgressIndicator
- jetpack compose - LinearProgressIndicator example
- jetpack compose - CircularProgressIndicator example
- jetpack compose - How to use TopAppBar
- jetpack compose - How to use BottomAppBar
- jetpack compose - BottomAppBar with FAB example