1

I've searched long time but I couldn't find the correct answer.

I have Resources/values/colors.xml I added <color name="colorBottomBar">#D0D0D0</color>

I want to set that color to my textview programmatically. I tried this.

txtBottomHome.SetTextColor(Resources.GetColor(Resource.Color.colorBottomBar));

But Resources.GetColor is deprecated.
Please help me.

Shreeya Chhatrala
  • 1,348
  • 15
  • 31
Passionate.C
  • 233
  • 3
  • 20

1 Answers1

1

I am not familiar with Xamarin, but in standard Android, Resources.getColor(int) was deprecated in favor of Resources.getColor(int, Theme). The backwards-compatible way to get a color, then, was ContextCompat.getColor(Context, int). Perhaps there is an equivalent in Xamarin.

Ben P.
  • 49,703
  • 5
  • 81
  • 113
  • Thanks for your answer. I've tried ContextCompat.getColor(Contex, int) too. but it says "cannot convert from 'int' to 'Android.Content.Res.ClorStateList'". – Passionate.C Jul 29 '17 at 05:52
  • textview.SetTextColor needs Android.Content.Res.ColorStateList as parameter. How can I get it from ContextCompat.getColor? – Passionate.C Jul 29 '17 at 05:55
  • Use `ContextCompat.getColorStateList()` instead – Ben P. Jul 29 '17 at 06:09