我正在创建一个水平字符串,在每个文本之间都有彩色项目符号。我使用 Spanned StringBuilder 并返回值为 Html.fromHtml(builder.toString()) 的方法。问题是如何使用该返回值在 TextView 中设置文本。
public class MainActivity extends AppCompatActivity {
TextView text;
StringBuilder builder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView)findViewById(R.id.text);
text.setText(Html.fromHtml(builder.toString()));
}
Spanned createSpannable(List<String> interests) {
builder = new StringBuilder();
int size = interests.size();
for (int i = 0; i < size; i++) {
builder.append(interests.get(i));
if (i < size - 1) {
builder.append(" <font color=\"#c52d08\">•</font> ");
}
}
return Html.fromHtml(builder.toString());
}
}