What is the purpose of the Text composable in Jetpack Compose?
The Text composable displays text on the screen. It is used to show simple or styled text in a Compose UI.
Click to reveal answer
beginner
How do you change the color of text in a Text composable?
You can change the text color by using the color parameter with a Color value, for example: Text("Hello", color = Color.Red).
Click to reveal answer
beginner
What parameter do you use to set the font size in a Text composable?
Use the fontSize parameter with a TextUnit value, like fontSize = 20.sp, to set the size of the text.
Click to reveal answer
beginner
How can you make text bold in a Text composable?
You can make text bold by setting the fontWeight parameter to FontWeight.Bold.
Click to reveal answer
beginner
What is the default behavior of the Text composable when the text is too long to fit in one line?
By default, the Text composable wraps the text to the next line to fit within its container.
Click to reveal answer
Which parameter changes the color of text in a Text composable?
Acolor
BfontSize
CfontWeight
DtextAlign
✗ Incorrect
The color parameter sets the text color.
How do you make text bold in a Text composable?
AfontWeight = FontWeight.Bold
BfontSize = 20.sp
Ccolor = Color.Black
DtextAlign = TextAlign.Center
✗ Incorrect
Setting fontWeight to FontWeight.Bold makes the text bold.
What happens if the text inside a Text composable is too long for one line by default?
AText is cut off
BText wraps to the next line
CText scrolls horizontally
DApp crashes
✗ Incorrect
By default, text wraps to the next line to fit the container.
Which unit is used to set font size in a Text composable?
Apx
Bdp
Cpt
Dsp
✗ Incorrect
Font size uses sp units for scalable pixels.
Which of these is NOT a parameter of the Text composable?
Atext
BfontWeight
CbackgroundColor
Dcolor
✗ Incorrect
backgroundColor is not a direct parameter of Text; background is set via modifiers.
Explain how to display styled text using the Text composable in Jetpack Compose.
Think about parameters that control appearance and behavior of text.
You got /5 concepts.
Describe what happens when the text content is longer than the available width in a Text composable and how you can control it.
Consider how text fits or cuts off inside its container.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the Text composable in Jetpack Compose?
easy
A. To display text on the screen
B. To create buttons
C. To handle user input
D. To manage app navigation
Solution
Step 1: Understand the role of Text composable
The Text composable is designed to show words or sentences visibly on the app screen.
Step 2: Compare with other UI elements
Buttons handle clicks, input fields take user input, and navigation manages screen changes, so these are not the Text composable's job.
Final Answer:
To display text on the screen -> Option A
Quick Check:
Text composable = display text [OK]
Hint: Text composable always shows text content [OK]
Common Mistakes:
Confusing Text with Button composable
Thinking Text handles user input
Assuming Text manages navigation
2. Which of the following is the correct syntax to display the text "Hello World" using the Text composable?
easy
A. Text: "Hello World"
B. Text(content = "Hello World")
C. Text("Hello World")
D. Text { "Hello World" }
Solution
Step 1: Recall Text composable syntax
The Text composable accepts the text content as the first positional parameter.
Step 2: Check each option
A uses invalid colon syntax. B correctly uses positional argument Text("Hello World"). C uses invalid content parameter. D uses lambda syntax which is incorrect for Text.
Final Answer:
Text("Hello World") -> Option C
Quick Check:
Text("string") = positional first arg [OK]
Hint: Use Text("your text") for simple display [OK]
Common Mistakes:
Using content= parameter name
Using colon instead of parentheses
Trying to pass text inside braces
3. What will be displayed on the screen when this code runs?
Text(text = "Welcome", fontSize = 24.sp, color = Color.Red)
medium
A. The word "Welcome" in default color and size
B. The word "Welcome" in red color with font size 24 sp
C. An error because fontSize is not a valid parameter
D. The word "Welcome" in blue color with font size 24 sp
Solution
Step 1: Understand parameters used
The fontSize parameter sets the text size, and color sets the text color. Both are valid for Text composable.
Step 2: Analyze the values
Font size is 24.sp (scaled pixels), color is Color.Red, so text appears red and sized 24 sp.
Final Answer:
The word "Welcome" in red color with font size 24 sp -> Option B
Quick Check:
fontSize and color change text appearance [OK]
Hint: fontSize and color change text look visibly [OK]
Common Mistakes:
Assuming default color is applied ignoring color param
Thinking fontSize is invalid
Confusing color values
4. Identify the error in this Text composable code:
Text(text = Hello World)
medium
A. fontSize parameter is required
B. Incorrect parameter name, should be content instead of text
C. Text composable cannot display multiple words
D. Missing quotes around the string "Hello World"
Solution
Step 1: Check string syntax
In Kotlin, string literals must be enclosed in double quotes. Here, "Hello World" is missing quotes.
Step 2: Validate parameter name and requirements
The parameter name text is correct. Text composable can display multiple words. fontSize is optional.
Final Answer:
Missing quotes around the string "Hello World" -> Option D
Quick Check:
Strings need quotes in Kotlin [OK]
Hint: Always put text strings inside double quotes [OK]
Common Mistakes:
Forgetting quotes around text
Using wrong parameter names
Thinking fontSize is mandatory
5. You want to display a greeting message that changes color based on a Boolean variable isMorning. Which code correctly uses the Text composable to show "Good Morning" in green if isMorning is true, otherwise "Good Evening" in blue?
hard
A. Text(text = if (isMorning) "Good Morning" else "Good Evening", color = if (isMorning) Color.Green else Color.Blue)
B. Text(text = "Good Morning" or "Good Evening", color = Color.Green or Color.Blue)
C. Text(text = "Good Morning" && "Good Evening", color = Color.Green && Color.Blue)
D. Text(text = isMorning ? "Good Morning" : "Good Evening", color = isMorning ? Color.Green : Color.Blue)
Solution
Step 1: Understand Kotlin conditional expressions
Kotlin uses if (condition) value1 else value2 for inline conditions, not the ternary operator.
Step 2: Analyze each option
Text(text = if (isMorning) "Good Morning" else "Good Evening", color = if (isMorning) Color.Green else Color.Blue) correctly uses Kotlin's if-else expressions for both text and color. Text(text = "Good Morning" or "Good Evening", color = Color.Green or Color.Blue) uses invalid syntax with 'or'. Text(text = "Good Morning" && "Good Evening", color = Color.Green && Color.Blue) uses '&&' which is logical AND, not for choosing values. Text(text = isMorning ? "Good Morning" : "Good Evening", color = isMorning ? Color.Green : Color.Blue) uses ternary operator syntax which Kotlin does not support.
Final Answer:
Text(text = if (isMorning) "Good Morning" else "Good Evening", color = if (isMorning) Color.Green else Color.Blue) -> Option A
Quick Check:
Kotlin uses if-else, not ?: for inline conditions [OK]
Hint: Use Kotlin if-else, not ?:, for inline conditions [OK]
Common Mistakes:
Using ?: ternary operator syntax
Using logical operators instead of conditions
Trying to combine strings or colors with 'or' or '&&'
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.