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 trialMUZ140831 Blessing Funani
654 Pointshow do l change background color to green
change back ground color to green
import android.os.Bundle;
import android.widget.TextView;
public class MealActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_meal);
TextView foodLabel = (TextView) findViewById(R.id.foodTextView);
TextView drinkLabel = (TextView) findViewById(R.id.drinkTextView);
RelativeLayout mealLayout = (RelativeLayout) findViewById(R.id.mealLayout);
RelativeLayout.setbackGroundColor(Color.GREEN);
}
}
2 Answers
Chase Marchione
155,055 PointsHi Blessing,
You'll want to make sure that you're setting the background color of the variable of type RelativeLayout, rather than RelativeLayout itself. Also, Java is a case sensitive language, so the setBackgroundColor method has to be spelled exactly that way when it is called.
mealLayout.setBackgroundColor(Color.GREEN);
Hope this helps!
cossy
17,748 Pointspublic 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);
// Add here
foodLabel.setTextColor(Color.BLUE);
drinkLabel.setTextColor(Color.GRAY);
}
}