Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Android.Resource.Color to Android.Graphics.Color

I have a value of Android.Resource.Color like Android.Resource.Color.HoloOrangeDark.
I want to covert it to a Android.Graphics.Color.
How can I do that?

like image 956
Code Pope Avatar asked Sep 23 '14 10:09

Code Pope


People also ask

What color is Android?

Android green is a shade of chartreuse or Caribbean green, defined by Google as the color of the "Android robot" logo for the Android operating system.

What color formats are supported for color resources in Android?

red(int) to extract the red component. green(int) to extract the green component. blue(int) to extract the blue component.

How to use color in Android?

Named Color Resources in Android (Note: To add a new resource first select the app in the Project explorer file. Then use the File or context menu, usually right-click, then the New option and select Android resource file. A color resource does not need to be stored in colors. xml, other file names can be used.)

How can I color code in Android Studio?

You can try this . File -> Settings -> Colors&Fonts -> Java(XML) -> change foreground you want on the right- top whee I tag. if you want change XML code color , you can find XML to change . You can download jar.


2 Answers

You can try this:

Resources.GetColor(Resource.Color.HoloOrangeDark);

UPDATE:
Resources.GetColor has been deprecated. You can use from ContextCompat like below:

ContextCompat.GetColor(mContext, Resource.Color.HoloOrangeDark);
like image 21
Naruto Uzumaki Avatar answered Sep 28 '22 08:09

Naruto Uzumaki


Resources.GetColor has been deprecated. Make sure you use ContextCompat.GetColor instead.

So

Resources.GetColor(Resource.Color.HoloOrangeDark);

Will become

int colorInt = ContextCompat.GetColor(this.Context, Resource.Color.HoloOrangeDark))

ContextCompat returns a int so to get a Color out of it just create a new color and pass in the int.

Color color = new Color(colorInt);
like image 89
Andres Castro Avatar answered Sep 28 '22 10:09

Andres Castro