Android碎碎念 -- 设置文字颜色

1.JAVA代码使用工具Html.fromHtml:
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
2.字符串处理Spannable:

TextView text = (TextView) findViewById(R.id.text_login);
text.setText("");
text.append("Add all your funky text in here");
Spannable text = (Spannable) text.getText();
text.setSpan(new BackgroundColorSpan(Color.RED), 1, 4, 0);

3.使用颜色值从XML资源:
int сolor = getResources().getColor(R.color.label_color);
String сolorString = String.format("%X", labelColor).substring(2);
Html.fromHtml(String.format("<font color=\"#\">text</font>", сolorString), TextView.BufferType.SPANNABLE); 
4.使用的WebView:
WebView webview = new WebView(this);
String summary = "<html><body>Sorry, <span style=\"background:red;\">Madonna</span> gave no results</body></html>";
webview.loadData(summary, "text/html", "utf-8");

你可能感兴趣的:(android,字体颜色)