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! While you're at it, check out some resources Treehouse students have shared here.

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 Java Improving Our Code Adding Colors

prosper nyamukondiwa
prosper nyamukondiwa
656 Points

help am lost on this one

Let's continue to add color to MealActivity. In the onCreate() method, set the text color of foodLabel to Color.BLUE. Then set the text color of drinkLabel to Color.GRAY.

MealActivity.java
public class MealActivity extends Activity {

    public TextView foodLabel;
    public TextView drinkLabel;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meal);

        foodLabel = (TextView) findViewById(R.id.foodTextView);
        drinkLabel = (TextView) findViewById(R.id.drinkTextView);
        RelativeLayout mealLayout = (RelativeLayout) findViewById(R.id.mealLayout);
        mealLayout.setBackgroundColor(Color.GREEN);
    }
}

Hi Prosper,

food label is of type TextView which has methods for setting the text color. It can be done like so;

foodLabel.text.setTextColor(Color.BLUE);

step1. we have stated the textView we want to target which is foodLabel step2. we have used .text method on foodLabel to say we would like to do something to the text. step3. we have used the .setTextColor to say we want to set the color of text. step4. we have passed in the Color.BLUE parameter as we need to let the method know what color to set it too.

Hope this helps a little and keep going !! :)

M

prosper nyamukondiwa
prosper nyamukondiwa
656 Points

thanks with the help michael but the problem still persists its still giving error

2 Answers

Hi Prosper;

If you haven't yet figured it out try this: foodLabel.setTextColor(Color.BLUE); drinkLabel.setTextColor(Color.GRAY);

Happy coding!!

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Prosper;

Were you able to get this resolved?

Ken