0
0
Android Kotlinmobile~20 mins

Text composable in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Text Composable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the output of this Text composable code?
Consider this Kotlin Compose code snippet:
Text(text = "Hello, Compose!", color = Color.Red, fontSize = 20.sp)

What will the user see on the screen?
Android Kotlin
Text(text = "Hello, Compose!", color = Color.Red, fontSize = 20.sp)
ANo text will be displayed because color must be set with a hex string.
BThe text "Hello, Compose!" displayed in default black color with font size 20sp.
CThe text "Hello, Compose!" displayed in red color with default font size.
DThe text "Hello, Compose!" displayed in red color with font size 20sp.
Attempts:
2 left
💡 Hint
Remember that the color parameter controls text color and fontSize controls size.
📝 Syntax
intermediate
2:00remaining
Which option will cause a syntax error in this Text composable usage?
Look at these Text composable calls. Which one will cause a syntax error?
AText(text = "Welcome", fontWeight = FontWeight.Bold, color = Color.Blue)
BText(text = "Welcome", fontWeight = Bold)
CText(text = "Welcome", fontWeight = FontWeight.Bold)
DText(text = "Welcome")
Attempts:
2 left
💡 Hint
Check if all parameters are properly referenced with their full names.
lifecycle
advanced
2:00remaining
What happens if you update the text parameter of a Text composable dynamically?
Suppose you have a state variable holding a string and you pass it to Text composable's text parameter. What happens when you update that state?
Android Kotlin
var message by remember { mutableStateOf("Hello") }
Text(text = message)
// Later message = "Hi"
AThe Text composable automatically re-renders to show the updated message.
BThe Text composable will not update until the app is restarted.
CThe Text composable shows both old and new messages simultaneously.
DThe Text composable throws a runtime error when the state changes.
Attempts:
2 left
💡 Hint
Think about how Compose handles state and recomposition.
navigation
advanced
2:00remaining
How to make a Text composable clickable to navigate to another screen?
You want to make a Text composable that when tapped navigates to a new screen. Which approach is correct?
AUse Text(text = "Click me", navigate = "destination") to specify navigation.
BSet Text's onClick parameter to navController.navigate("destination").
CWrap Text in a Clickable modifier and call navController.navigate("destination") inside onClick.
DText composable cannot be clickable; use Button instead.
Attempts:
2 left
💡 Hint
Modifiers can add click behavior to composables.
🔧 Debug
expert
2:00remaining
Why does this Text composable not show the expected color?
Given this code:
Text(text = "Hello", color = Color(255, 0, 0))

The text appears black instead of red. Why?
Android Kotlin
Text(text = "Hello", color = Color(255, 0, 0))
AColor constructor expects values from 0f to 1f floats, not 0-255 integers.
BColor constructor is deprecated and ignored by Text composable.
CText composable only accepts predefined colors like Color.Red.
DThe color parameter must be a hex string, not a Color object.
Attempts:
2 left
💡 Hint
Check the expected parameter types for Color constructor in Compose.