是否可以为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. // …
我正在寻找一种方法来改变在一个字的文本的颜色TextView从内Activity.
例如,有了这个:
String first = "This word is ";
String next = "red"
TextView t = (TextView) findViewById(R.id.textbox);
t.setText(first + next);
Run Code Online (Sandbox Code Playgroud)
如何将next文本颜色更改为红色?
我想显示'123',但是1为红色2,绿色为3,黑色为3 ......这是可能的,还是有其他推荐的方式在同一文本视图中显示不同的文字颜色...