How can I get value of color programmatically from colors.xml file into C# code?
Here is my colors.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<item name="row_a" type="color">#FFCCFFCC</item>
<item name="row_b" type="color">#FFFFFFCC</item>
<item name="all_text" type="color">#FF000000</item>
<item name="row_red" type="color">#FFFF4444</item>
<item name="row_orange" type="color">#FFE69900</item>
<item name="row_green" type="color">#FF739900</item>
<item name="wheat" type="color">#FFF5DEB3</item>
<integer-array name="androidcolors">
<item>@color/row_a</item>
<item>@color/row_b</item>
<item>@color/all_text</item>
<item>@color/row_red</item>
<item>@color/row_orange</item>
<item>@color/row_green</item>
<item>@color/wheat</item>
</integer-array>
</resources>
I tried:
Color t = (Color)Resource.Colors.wheat;
but of course I cannot convert int value to Color this way.
EDIT:
As suggested I tried
Color t = Resources.GetColor(Resource.Color.row_a);
But it gives me an error:
Error CS0120 An object reference is required for the non-static field,
method, or property 'Resources.GetColor(int)'
Try this code:
Color t = new Android.Graphics.Color (ContextCompat.GetColor (this, Resource.Color.row_a));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With