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

Katherine Goh
Katherine Goh
3,856 Points

Working with Android- FunFactActivity changing of background colors using drawable (customise background) .

package com.sp.funfacts;

import android.graphics.Color;

import java.util.Random;

public class ColorWheel { //Fields (member Variables) - Properties about the object private String[] mColor = { /* "#39add1", //light blue "#3079ab", //dark blue "#c25975", //mauve "#e15258", //red "#f9845b", //orange "#838cc7", //lavander "#7d669e", //purple "#53bbb4", //aqua "#51b46d", //green "#e0ab18", //mustard "#637a91", //dark grey "#f092b0", //pink "#b7c0c7", //light grey*/

//how do we input (R.drawable.bg_1)....... and the other drawable.bg_9?

};
// Method - Actions the object can take
public int getColor() {
    String color;
    //randomly selects a color
    Random randomgenerator = new Random();
    int randomNumber = randomgenerator.nextInt(mColor.length);
    color= mColor[randomNumber] ;
    int colorAsInt= Color.parseColor(color);
    return colorAsInt;
}

}