如何在 Android 中突出显示 TextView [英] How to highlight TextView in Android
本文介绍了如何在 Android 中突出显示 TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想突出显示一个 TextView
并实现如下所示的设计.有谁知道如何使用 TextView
实现这一目标?我从现有的 Android 应用中截取了此屏幕截图.
I would like to highlight a TextView
and achieve the design shown below.
Does anyone know how to achieve this using a TextView
?
I took this screenshot from an existing Android app.
通过使用此代码,我得到如下所示的结果,这不是我想要的:
By using this code I get results shown below, which is not what I want:
sp.setSpan(new BackgroundColorSpan(color), start, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
推荐答案
您需要使用 Spannable String:
You need to use a Spannable String:
TextView textView = (TextView)findViewById(R.id.textView1);
String text = "Test";
Spannable spanText = Spannable.Factory.getInstance().newSpannable(text);
spanText.setSpan(new BackgroundColorSpan(0xFFFFFF00), 14, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spanText);
试试这个.这会奏效.
这篇关于如何在 Android 中突出显示 TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文