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 trialNathan Bird
2,189 PointsUsing .setBackground() in android studio
I have this line of code:
winner.setBackground();
but what exactly am I supposed to put in the parentheses?
1 Answer
Pushparaj Samant
4,607 PointsYou are supposed to specify the color you want to set to the background. It should be a integer value so if you have HEX value convert it to integer using Color.parseColor method to convert it to integer and then set inside those paranthesis
Nathan Bird
2,189 PointsNathan Bird
2,189 PointsYes, but in android studio auto complete gives me this:
image.setBackground(Drawable background)
Pushparaj Samant
4,607 PointsPushparaj Samant
4,607 PointsThats alright. Just delete that and insert your integer value and try.
Nathan Bird
2,189 PointsNathan Bird
2,189 PointsI'm trying to set a background image not a background color.
winner.setBackground(Color.WHITE); // This does not work because .setBackground() is asking for a drawable image!
winner.setBackgroundColor(Color.WHITE); // this is the way to set a Background Color
Nathan Bird
2,189 PointsNathan Bird
2,189 PointsOnly problem now is the path name! The Java file and the activity.xml file are in completely different folders!