【问题标题】:Text color gradient in textview not workingtextview中的文本颜色渐变不起作用
【发布时间】:2012-08-29 12:06:55
【问题描述】:

我想在我的TextView 中设置渐变文本颜色。我已经使用了这个代码

Shader textShader=new LinearGradient(0, 0, 0, 20, new int[]{Color.rgb(225, 225, 225),Color.rgb(150, 150, 150)}, new float[]{0, 1}, TileMode.CLAMP);
text.getPaint().setShader(textShader);

启动活动时,文本不显示。但如果我改变手机的方向,它会以渐变色显示TextView 中的文本。我已经在 HTC One V 上测试过了。它在模拟器和三星设备上运行良好。

我也测试了下面的例子,也出现了同样的问题。

https://github.com/koush/Widgets

【问题讨论】:

  • 设置shader后有没有给text.invalidate();打电话?

标签: android textview linear-gradients


【解决方案1】:
.text1 {    background: #dfdfdf; /* Old browsers */
background: -moz-linear-gradient(top,  #d1d1d1 0%, #000 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#d1d1d1), color-stop(100%,#000)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #d1d1d1 0%,#000 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #d1d1d1 0%,#000 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #d1d1d1 0%,#000 100%); /* IE10+ */
background: linear-gradient(to bottom,  #d1d1d1 0%,#000 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d1d1d1', endColorstr='#000',GradientType=0 ); /* IE6-9 */
    -webkit-text-fill-color: transparent;
    -webkit-background-clip: text;
    -webkit-animation-name: masked-animation;
    -webkit-animation-duration: 10s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: linear;
}
h1{color:#f00;}


<div class="text1"><h1>Lorem</h1></div>

【讨论】:

  • 它工作正常,请签入一个 safari。通常所有的移动设备都支持 chrome 和 safri。
  • 这与android无关!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-05
  • 2019-10-06
  • 2019-02-22
  • 1970-01-01
  • 2021-07-20
  • 1970-01-01
相关资源
最近更新 更多