Examples of setting colours dynamically

Buttons and textviews.

button.setBackgroundColor(Color.parseColor("#bdbdbd"));

yourTextView.setTextColor(0xffbdbdbd);
textView.setTextColor(getResources().getColor(R.color.sf_yellow));

Where colors.xml (in values folder) contains

<resources>
    <color name="sf_yellow">#f5e214</color>    
</resources>

On canvas simply:

canvas.drawColor(Color.BLUE);

or for greater control:

float[] color=new float[3]; // HSV (0..360,0..1,0..1) 
//color[0]=(float)(Math.random()*360);  
color[0]=197;  
color[1]=1;  
color[2]=1; 
canvas.drawColor(Color.HSVToColor(color));

 

This entry was posted in Android. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *