希望有多个文本显示风格单一的TextView [英] wants to have multiple text display styles in a single textview
本文介绍了希望有多个文本显示风格单一的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的一个Android应用程序,我想知道我可以做几句大胆定期和斜体很少,比如我有一个文本HELLOO一个TextView现在我想显示在文本视图像这样的文本
I am working on an android app i want to know how i can make few words in bold regular and few in italic for example i have a textview with a text HELLOO now I want to display the text like this in a text view
HELL OO 的
请告诉我如何通过Android的风格,以实现这一目标?
please tell me how to achieve this through styles in android??
推荐答案
我说,你有一个TextView即 ETX ,请使用以下code:
Say, you have a TextView namely etx, use the following code:
final SpannableStringBuilder sb = new SpannableStringBuilder("HELLOO");
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text bold
final StyleSpan iss = new StyleSpan(android.graphics.Typeface.ITALIC);Span to make text italic
sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold
sb.setSpan(iss, 4, 6, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make last 2 characters Italic
etx.setText(sb);
使用这种方法的主要优点是,可以动态地设置文本格式。
The main advantage of using this approach is that you can format text dynamically.
这篇关于希望有多个文本显示风格单一的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文