How to convert Android.Resource.Color to Android.Graphics.Color
13,653
Solution 1
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);
Solution 2
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);
Related videos on Youtube
![Code Pope](https://i.stack.imgur.com/eb1zv.jpg?s=256&g=1)
Author by
Code Pope
Software developer for more than a decade. "From my point of view, code is the light that illuminates the darkness, even if it does not dissolve it, and a spark of divine light is within each of us."
Updated on July 08, 2022Comments
-
Code Pope almost 2 years
I have a value of
Android.Resource.Color
likeAndroid.Resource.Color.HoloOrangeDark
.
I want to covert it to aAndroid.Graphics.Color
.
How can I do that?-
Code Pope almost 10 years@pskink
Android.Resource.Color
is an enum value in Xamarin.Android representing constant integers for the Android.R.Color class in Android. SoAndroid.Resource.Color
is equal to theAnroid.R.Color
in Android. The values are constant integers. -
pskink almost 10 yearsso Resources.getColor() should probably work
-
-
Mohammad Afrashteh about 6 yearsthis.Context not exist!
-
CDrosos about 6 yearsso just use this on activities. this.Context is usually used of fragments