MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
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.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MainContent()
}
}
@Composable
fun MainContent(){
Column(
Modifier
.padding(16.dp)
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(onClick = {
Toast.makeText(
this@MainActivity,
"Clicked",
Toast.LENGTH_SHORT
).show()
}) {
Text(text = "Click Me" )
}
Spacer(modifier = Modifier.requiredHeight(25.dp))
Text(
text = "This is a Text",
fontWeight = FontWeight.Bold,
fontSize = 25.sp,
fontFamily = FontFamily.Serif
)
Text(
text = "This is second Text",
fontWeight = FontWeight.Bold,
fontSize = 25.sp,
fontFamily = FontFamily.Monospace,
color = Color.Red
)
Text(
text = "This is third Text",
fontWeight = FontWeight.Bold,
fontSize = 35.sp,
fontFamily = FontFamily.Cursive,
color = Color(0xFF0047AB)
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - How to use Text
- jetpack compose - ClickableText example
- jetpack compose - How to use Button
- jetpack compose - How to use TextField
- jetpack compose - OutlinedTextField example
- jetpack compose - Password TextField example
- jetpack compose - Handle changes in a TextField
- jetpack compose - How to use Card
- jetpack compose - How to use Checkbox
- jetpack compose - How to use RadioButton
- 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