import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
@Composable
fun ComposeIntroductionScreen(onClose: () -> Unit) {
Scaffold(
topBar = {
TopAppBar(
title = { Text("Compose Introduction") }
)
},
content = { paddingValues ->
Column(
modifier = Modifier
.padding(paddingValues)
.padding(16.dp)
.fillMaxSize()
) {
Text("Why Compose?", style = MaterialTheme.typography.titleMedium)
Spacer(modifier = Modifier.height(12.dp))
val reasons = listOf(
"Declarative UI",
"Less Code",
"Kotlin Integration",
"Fast UI Updates",
"Easy Theming"
)
reasons.forEach { reason ->
Text("- $reason", style = MaterialTheme.typography.bodyLarge, modifier = Modifier.padding(vertical = 4.dp))
}
Spacer(modifier = Modifier.weight(1f))
Button(
onClick = onClose,
modifier = Modifier.fillMaxWidth()
) {
Text("Close")
}
}
}
)
}
@Preview(showBackground = true)
@Composable
fun PreviewComposeIntroductionScreen() {
ComposeIntroductionScreen(onClose = {})
}This screen uses Jetpack Compose to build the UI entirely in Kotlin code without XML.
The Scaffold provides a basic layout with a TopAppBar showing the screen title.
The main content is a Column with a title text, a list of reasons displayed as bullet points, and a Button labeled 'Close' at the bottom.
The button calls the onClose callback when clicked, allowing the screen to be closed or navigated away.
This example highlights Compose's declarative style and Kotlin integration, showing why it is modern and concise.