首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android富文本标记

Android富文本标记
EN

Stack Overflow用户
提问于 2018-11-14 07:03:07
回答 3查看 1.6K关注 0票数 4

我正在寻找一个关于使用Mark创建富文本的库或优化示例。

例如,需要转向的东西:

1-* -> Bold

2- _Italic_ ->意大利语

很长的例子:

3- _Hello_ *World* -> Hello World

诸若此类。

我见过很多应用程序使用它,比如不和谐,Whatsapp,Skype。

我也做过类似的事情,但我知道它不是经过优化的,可能会导致运行时错误。

EN

回答 3

Stack Overflow用户

发布于 2018-11-14 07:09:14

你不需要任何额外的图书馆..。

只要看看android.text.SpannableStringBuilder..。

这将允许您获得以下文本功能:

  • 让它变大
  • 粗体
  • 加下划线
  • 斜体化
  • 打穿
  • 有色的
  • 突出显示
  • 显示为上标
  • 显示为下标
  • 显示为链接
  • 让它可点击。

这里有一个关于如何将Bold样式应用于TextView中的单词的示例:

代码语言:javascript
复制
String text = "This is an example with a Bold word...";  

// Initialize a new SpannableStringBuilder instance
SpannableStringBuilder strb = new SpannableStringBuilder(text);

// Initialize a new StyleSpan to display bold text
StyleSpan bSpan = new StyleSpan(Typeface.BOLD);

// The index where to start applying the Bold Span
int idx = text.indexOf("Bold");

strb.setSpan(
                bSpan, // Span to add
                idx, // Start of the span
                idx + 4, // End of the span 
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        );

// Display the spannable text to yourTextView
yourTextView.setText(ssBuilder);        
票数 4
EN

Stack Overflow用户

发布于 2018-11-14 07:09:57

Stack Overflow用户

发布于 2018-11-14 07:54:57

代码语言:javascript
复制
SpannableStringBuilder str = new SpannableStringBuilder("Your awesome text");
str.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), start_int, end_int, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView tv=new TextView(context);
tv.setText(str);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53294724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档