I am trying to use colors created in my res/values/colors.xml
file. But when I make the call dynamically the program doesn't compile and instead recommends: Should pass resolved color instead of a resource id.
Color Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="gold">#857500</color>
<color name="green">#0B3B0B</color>
</resources>
Activity Code:
title.setTextColor(R.color.green);
help.setTextColor(R.color.gold);
settings.setTextColor(R.color.gold);
logout.setTextColor(R.color.gold);
profile.setTextColor(R.color.green);
Change the code to the following:
title.setTextColor(getResources().getColor(R.color.green));
help.setTextColor(getResources().getColor(R.color.gold));
settings.setTextColor(getResources().getColor(R.color.gold));
logout.setTextColor(getResources().getColor(R.color.gold));
profile.setTextColor(getResources().getColor(R.color.green));
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