試試這個
public static Spannable setFourDifferentFontStyle(final Context context, String original,
String firstWord, String color1, float size,
String secondWord, String color2, float size2,
String thirdWord, String color3, float size3,
String fourthWord, String color4, float size4)
{
// Create a new spannable with the two strings
Spannable spannable = new SpannableString(firstWord + secondWord + thirdWord + fourthWord);
spannable.setSpan(new RelativeSizeSpan(size), 0, firstWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new ForegroundColorSpan(Color.parseColor(color1)), 0, firstWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new RelativeSizeSpan(size2), firstWord.length(), firstWord.length() + secondWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new ForegroundColorSpan(Color.parseColor(color2)), firstWord.length(),firstWord.length() + secondWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new RelativeSizeSpan(size3), firstWord.length() + secondWord.length(), firstWord.length() + secondWord.length() + thirdWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new ForegroundColorSpan(Color.parseColor(color3)), firstWord.length() + secondWord.length(),firstWord.length() + secondWord.length() + thirdWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new RelativeSizeSpan(size4), firstWord.length() + secondWord.length() + thirdWord.length(), original.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new ForegroundColorSpan(Color.parseColor(color4)), firstWord.length() + secondWord.length() + thirdWord.length(), original.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
下載項目你可以使用** **網頁視圖,而不是一個TextView。並用一些** html文件填充它的內容,這些**文件存儲在assets文件夾中。確實很簡單。 –
@ ArtooDetoo,thanx你的答案。是的,我知道我應該使用webview的HTML文件,但我想問問怎麼用另一種方式?意味着可能不使用html代碼? – ertan2002
你**最好的選擇**是一個WebView。但是,如果你真的想使用Textview ...看到[this](http://stackoverflow.com/questions/2116162/how-to-display-html-in-textview) –