Issue
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)'
Solution
Problem was that I tried to access Resources from ListView Adapter. Solution is to use:
parent.Resources.GetColor(Resource.Color.row_a)
where parent
is passed into public override View GetView(int position, View convertView, ViewGroup parent)
method.
Answered By - Marcin Zdunek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.