2013-03-13 36 views
3

我想在我的TextView中使用Shader和LinearGradient添加线性渐变。这只在使用Color.LTGRAY,Color.MAGENTA等标准颜色时才起作用。如果使用我的custom_colors.xml中的颜色,则不显示渐变。任何想法如何使这项工作的自定义颜色?Android:用户界面:LinearGradient不使用自定义颜色

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); 

下面是custom_colors.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="el_maroon">#CD2990</color> 
    <color name="el_amethyst">#9D6B84</color> 
</resources> 

回答

2

试试这个:

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); 
+0

由于一吨。现在工作正常。 – Ankit 2013-03-13 16:04:16