I am trying to add linear gradient to the text in my TextView using Shader and LinearGradient. This is working only if I use standard colors like Color.LTGRAY, Color.MAGENTA, etc. No gradient is shown if I use colors from my custom_colors.xml. Any ideas how can I make this work for custom colors?
Shader txtShad=new LinearGradient(0, 0, 0, 10, new int[]{R.color.el_amethyst,R.color.el_maroon}, null, TileMode.MIRROR);
textview_dummy.getPaint().setShader(txtShad);
Below is the custom_colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="el_maroon">#CD2990</color>
<color name="el_amethyst">#9D6B84</color>
</resources>
To set the color of the TextView, you can also use Gradient color by using the LinearGradient. The parameters of the LinearGradient are: x0: x-coordinate for start of gradient line. It is of type float.
Try this:
Shader txtShad = new LinearGradient(0, 0, 0, 10, new int[] { getResources().getColor(R.color.el_amethyst), getResources().getColor(R.color.el_maroon) }, null, TileMode.MIRROR);
TL;DR you need to resolve the color resources first
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