是否可以为TextView中的不同文本设置多个样式?
例如,我将文本设置如下:
tv.setText(line1 + "\n" + line2 + "\n" + word1 + "\t" + word2 + "\t" + word3);
Run Code Online (Sandbox Code Playgroud)
是否可以为每个文本元素设置不同的样式?例如,line1粗体,word1斜体等.
开发人员指南的常见任务和Android中的操作方法包括选择,突出显示或设置部分文本样式:
Run Code Online (Sandbox Code Playgroud)// Get our EditText object. EditText vw = (EditText)findViewById(R.id.text); // Set the EditText's text. vw.setText("Italic, highlighted, bold."); // If this were just a TextView, we could do: // vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE); // to force it to use Spannable storage so styles can be attached. // Or we could specify that in the XML. // …
有人可以清楚地举例解释每个的跨度标志像SPAN_EXCLUSIVE_EXCLUSIVE和SPAN_MARK_MARK意思,什么时候用什么标志?
当它说:我不明白官方文件:
类型的跨度
SPAN_EXCLUSIVE_EXCLUSIVE不会扩展为包括在其起点或终点插入的文本.
"扩展到包含"是指插入跨度后进行的编辑吗?
这是否意味着这些标志不会影响具有不可变文本的Spannables?
如果我有一个SpannedString(或SpannableString)这样的
SpannableString spannableString = new SpannableString("Hello World!");
ForegroundColorSpan foregroundSpan = new ForegroundColorSpan(Color.RED);
BackgroundColorSpan backgroundSpan = new BackgroundColorSpan(Color.YELLOW);
spannableString.setSpan(foregroundSpan, 1, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(backgroundSpan, 3, spannableString.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannableString);
Run Code Online (Sandbox Code Playgroud)
我将如何在结果的范围内循环String?