Build: Simple Text Screen
This screen shows a simple text message centered on the screen using Jetpack Compose Text composable.
Target UI
--------------------- | | | | | Hello, Compose! | | | | | ---------------------
--------------------- | | | | | Hello, Compose! | | | | | ---------------------
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @Composable fun SimpleTextScreen() { Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ) { // TODO: Add Text composable here } }
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @Composable fun SimpleTextScreen() { Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ) { Text( text = "Hello, Compose!", fontSize = 24.sp, modifier = Modifier.padding(16.dp) ) } }
We use a Box to fill the whole screen and center its content both horizontally and vertically using contentAlignment = Alignment.Center. Inside the Box, we add a Text composable with the string "Hello, Compose!". We set the font size to 24sp for clear visibility and add 16dp padding around the text to keep some space from edges. This creates a simple centered text screen using Jetpack Compose.
--------------------- | | | | | Hello, Compose! | | | | | ---------------------
Text composable in Jetpack Compose?content parameter. D uses lambda syntax which is incorrect for Text.Text(text = "Welcome", fontSize = 24.sp, color = Color.Red)
fontSize parameter sets the text size, and color sets the text color. Both are valid for Text composable.Text(text = Hello World)
text is correct. Text composable can display multiple words. fontSize is optional.isMorning. Which code correctly uses the Text composable to show "Good Morning" in green if isMorning is true, otherwise "Good Evening" in blue?if (condition) value1 else value2 for inline conditions, not the ternary operator.Pass the test and this pattern moves unknown