我正在寻找一个关于使用Mark创建富文本的库或优化示例。
例如,需要转向的东西:
1-* -> Bold
2- _Italic_ ->意大利语
很长的例子:
3- _Hello_ *World* -> Hello World
诸若此类。
我见过很多应用程序使用它,比如不和谐,Whatsapp,Skype。
我也做过类似的事情,但我知道它不是经过优化的,可能会导致运行时错误。
发布于 2018-11-14 07:09:14
你不需要任何额外的图书馆..。
只要看看android.text.SpannableStringBuilder..。
这将允许您获得以下文本功能:
这里有一个关于如何将Bold样式应用于TextView中的单词的示例:
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); 发布于 2018-11-14 07:09:57
发布于 2018-11-14 07:54:57
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);https://stackoverflow.com/questions/53294724
复制相似问题