TEL:400-8793-956
当前位置:程序、服务器

如何以不同的颜色显示单个textview?

提问者: 近期获赞: 浏览人数: 发布时间:2021-01-30 13:38:36

 问:这个 <string name="disclaim">DISCLAIMER:Next Vision Research Solutions Pvt. Ltd. holds the right of refusal/cancel/acceptance of the junk responses either intentionally or unintentionally submitted by anyone and Next Vision Research Solutions Pvt. Ltd. will not be held liable to pay for any such junk responses. Payment shall be made only after ensuring the quality /authenticity on certain parameters of the submitted responses. We are bound to ensure 100 % quality across India with zero tolerance on fudging.                                         "</string>

我想在单个textview中显示此内容,但使用其他颜色(例如免责声明)显示:红色,其他剩余文本显示为黑色。
 
是否可以不使用更多的textview?
 
请告诉我任何可能的解决方案。
 
 
答:您可以使用以下代码:-
在您的情况下startIndex 是0并且 endIndex 是9
TextView TV = (TextView)findViewById(R.id.mytextview01);
 
Spannable wordtoSpan = new SpannableString("your string");        
 
wordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), startIndex, EndIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 
TV.setText(wordtoSpan);
上一篇: Android:如何在片段中添加Google Map?
下一篇: 按钮特定条件下的CTA逻辑会在WP中执行吗?