import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: android.os.Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MainScreen()
}
}
}
@Composable
fun MainScreen() {
Scaffold(
topBar = {
TopAppBar(
title = { Text(text = "Welcome Screen") }
)
},
content = { paddingValues ->
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(text = "Hello, User!")
}
}
)
}
@Preview(showBackground = true)
@Composable
fun PreviewMainScreen() {
MainScreen()
}This solution uses Scaffold as the main layout container, which provides slots for common UI elements like the TopAppBar. The TopAppBar displays the title "Welcome Screen" at the top. The body content uses a Box with fillMaxSize() to take all available space and centers the Text widget with the greeting message "Hello, User!". This layout is simple and follows Android Compose best practices for a basic screen structure.