【问题标题】:Text in TextView: Color and Transparency using HTMLTextView 中的文本:使用 HTML 的颜色和透明度
【发布时间】:2015-12-04 21:39:37
【问题描述】:

我正在尝试以不透明度为 75% 的白色在 Textview 中编写文本,但我得到的文本是黑色的,尽管在 HTML 页面中测试它时它工作正常。为什么会这样?

代码:

String text = "<span style=\"color: #ffffff; opacity: 0.75;\">Text </span>";
myTextView.setText(Html.fromHtml(text));

【问题讨论】:

  • ForegroundColorSpan docs

标签: android html colors textview opacity


【解决方案1】:

像这样更改你的代码

String text = "<span >Text </span>";
myTextView.setText(Html.fromHtml(text));   
myTextView.setTextColor(Color.WHITE);
myTextView.setAlpha(Float.parseFloat("0.75"));

【讨论】:

  • 其实我想设置不同的颜色和不透明度
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-16
  • 2014-11-23
  • 1970-01-01
相关资源
最近更新 更多