androidandroid-color

How to pass custom values to Color.rgb(red: 0,green: 0,blue: 0)


I have to mix colors in a view.Therefore I want to pass custom values to Color.rgb(0,0,255) function

Using Integer Variable will solve the above issue, But I am not able to pass the incremented value to my view.

A little description of what I want to do is:

View v; //to show the color by function Color.rgb()

int red,green,blue; //to change values of R,G,B respectively int selectedColor = Color.rgb(red, green, blue) //used variable for color v.setBackground(selectedColor)

//let's say I am increasing red value Button add; // to increase red value Button Sub; //to decrease red value

Now, I am stuck with the thing that when I am incrementing the value of red in onClick() function that value is not passing to {selectedColor = Color.rgb(red, green,blue)}. After Incrementing the value of red variable how to pass this red value to selectedColor Variable.?


Solution

  • You can simply use

    Color.rgb()
    

    or if you need to use alpha channel use

    Color.argb()