Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App with Kotlin Improving Our Code Adding Colors

Alfredo Ferreira
Alfredo Ferreira
546 Points

i tried everything but it doest not work

i put foodLabel.setTextColor(Color.BLUE) drinkLabel.setTextColor(Color.GRAY)

import android.app.Activity
import android.os.Bundle
import android.widget.TextView
import android.widget.RelativeLayout

class MealActivity : Activity() {
  override fun onCreate(savedInstanceState: Bundle) {


    val foodLabel = findViewById(R.id.foodTextView) as TextView
    val drinkLabel = findViewById(R.id.drinkTextView) as TextView
    val mealLayout = findViewById(R.id.mealLayout) as RelativeLayout
    mealLayout.backgroundColor = Color.RED


1 Answer

Hi there,

You want to use the property textColor on both the labels and assign the relevant color to them using an equals sign. Use dot notation on the label name just like the example on the line above, which sets the backgroundColor property in the same way:

    mealLayout.backgroundColor = Color.RED
    foodLabel.textColor = Color.BLUE
    drinkLabel.textColor = Color.GRAY