Setting the background of my textView as a color from 3 integers

    public void changeColor(){

    TextView changeColorText = (TextView) findViewById(R.id.textView2);
    changeColorText.setBackgroundColor(0xFFFF0000);

}

My goal here is to take 3 integers and make them into a color. I see that its put into hexadecimal number and the one that I have outputs red. So does this mean with the three integers that I have, i have to convert them into hex? If so how would i convert decimal into hex? Ive researched a few ways to do this, but none of them seem to be what i'm looking for. I have 3 integers so far that only go up to 255, which i assume is correct. Is there an equation that I am missing?

Answers


the three integers that you have are the RGB (Red Green Blue) i presume. Since they go unto 255. Try this

changeColorText.setBackgroundColor(Color.rgb(255,0,255)); //sets the color to purple

  1. Red 255
  2. Green 0
  3. Blue 255

You should be able to set the background with RGB. Try something like this :

changeColorText.setBackgroundColor(Color.rgb(r, g, b));

Where r g and b are your color values (red, green, and blue). I'm assuming the number's your pulling are RGB values as each one is a set number between 0-255


Need Your Help

Java XOM canonicalization - spurious characters

java xml

I am using XOM to canonicalize some XML. But there are some strange characters prepended to the output. The core of the code is as follows:

How do you add an UIImage to a MSMutableArray in Objective-C?

iphone objective-c ios5

I have noob objective-c question. How do you add an UIImage to a MSMutableArray? Here is the code that I have: