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.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
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 = Modifier
.background(Color(0xFFEFDFBB))
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center
) {
Text(
text = stringResource(
id = R.string.congratulation,
"marriage",
2021
),
fontSize = 35.sp,
fontFamily = FontFamily.Serif,
textAlign = TextAlign.Center,
color = Color(0xFFD71868),
fontWeight = FontWeight.Bold
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
res/values/strings.xml
<resources>
<string name="app_name">Compose - String Resource formatting</string>
<string name="congratulation">Happy %1$s anniversary %2$d</string>
</resources>
- jetpack compose - Cut corner shape example
- jetpack compose - Image from drawable
- jetpack compose - Image clickable
- jetpack compose - Image border
- jetpack compose - Image gradient border
- jetpack compose - Image shape
- jetpack compose - Image tint
- jetpack compose - Image scale
- jetpack compose - Image from assets folder
- jetpack compose - How to use LazyColumn
- jetpack compose - How to use LazyRow
- jetpack compose - Accessing string resources
- jetpack compose - String resource plurals
- jetpack compose - Get dimension resource
- jetpack compose - Get color resource