如何设置渐变为一个TextView的文本颜色? [英] How to set gradient as the text color of a TextView?
本文介绍了如何设置渐变为一个TextView的文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含在我的文件夹绘制渐变( textgradient.xml
)的文件。我需要把这个渐变为的TextView
通过Java的文本颜色。那怎么办?
解决方案
TextView的secondTextView =新的TextView(本);
着色textShader =新的LinearGradient(0,0,0,20,
新的INT [] {Color.GREEN,Color.BLUE},
新浮法[] {0,1},TileMode.CLAMP);
secondTextView.getPaint()setShader(textShader)。
I have a file containing a gradient( textgradient.xml
) in my drawable folder. I need to put this gradient as the text color of a TextView
through Java. How to do that?
解决方案
TextView secondTextView = new TextView(this);
Shader textShader=new LinearGradient(0, 0, 0, 20,
new int[]{Color.GREEN,Color.BLUE},
new float[]{0, 1}, TileMode.CLAMP);
secondTextView.getPaint().setShader(textShader);
这篇关于如何设置渐变为一个TextView的文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文