Not*_*bad 9 string android android-widget
反正有没有在android中设置字符串资源的颜色?我的意思是,我知道我可以使用一些html标签来改变字符串样式(或子字符串),但没有发现任何改变颜色.我在stackoverflow中看到过其他解决方案,比如在设置文本之前将字符串传递给Html.fromHtml(字符串),但我想在字符串资源编辑器中执行此操作.有可能吗?
Kap*_*apé 20
看起来这个方法有效:
<string name="some_text">this is <font fgcolor="#ffff0000">red</font></string>
Run Code Online (Sandbox Code Playgroud)
Nor*_*man 11
据我所知,这是不可能的.我会使用SpannableString来改变颜色.
int colorBlue = getResources().getColor(R.color.blue);
String text = getString(R.string.text);
SpannableString spannable = new SpannableString(text);
// here we set the color
spannable.setSpan(new ForegroundColorSpan(colorBlue), 0, text.length(), 0);
Run Code Online (Sandbox Code Playgroud)
Spannable非常好.您可以将think设置为fontseize和stuff,并将其附加到文本视图中.优点是您可以在一个视图中使用不同的颜色.
编辑:好的,如果你只想设置上面提到的解决方案的颜色我就是你要走的路.
| 归档时间: |
|
| 查看次数: |
17433 次 |
| 最近记录: |