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.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(0xFFE8CCD7))
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center
) {
Text(
text = stringResource(id = R.string.hello),
fontSize = 55.sp,
fontFamily = FontFamily.Serif,
textAlign = TextAlign.Center
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
res/values/strings.xml
<resources>
<string name="app_name">Compose - String Resources</string>
<string name="hello">Hello Jetpack Compose</string>
</resources>
- jetpack compose - String resource positional formatting
- jetpack compose - String resource plurals
- jetpack compose - Get dimension resource
- jetpack compose - Get color resource
- jetpack compose - Text custom font
- jetpack compose - Accessing font resource
- jetpack compose - LazyColumn scroll to top bottom
- jetpack compose - LazyColumn smooth scrolling
- jetpack compose - Animate content size
- jetpack compose - FadeIn FadeOut animation
- jetpack compose - Animation duration
- jetpack compose - animateFloatAsState
- jetpack compose - Repeatable animation
- jetpack compose - Snap animation
- jetpack compose - AnimateColorAsState