//使用動態SpannableString更改字體
Typeface tfaerial=Typeface.createFromAsset(getAssets(),"fonts/aerial.ttf");
Typeface tfTradeGothicLight=Typeface.createFromAsset(getAssets(), "fonts/TradeGothic-Light.OTF");
String strt_dialog_desc=this.getResources().getString(R.string.strt_dialog_desc);
int upto=strt_dialog_desc.indexOf(".");
if (strt_dialog_desc!=null)
{
aboutAuthTV.setTextColor(Color.BLACK);
aboutAuthTV.setLineSpacing(1.2f, 1.5f);
aboutAuthTV.setTextSize(23);
SpannableString SS = new SpannableString(strt_dialog_desc);
SS. setSpan (new StyleSpan(tfTradeGothicLight.getStyle()), 0, upto,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
SS. setSpan (new StyleSpan(tfaerial.getStyle()), upto, strt_dialog_desc.length(),Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
yourtextView.setText(SS);
}
//這個以這種方式改變字體改變顏色notworking
String str="<font size =\"20\"><B>Bold</B> <br/> Then Normal Text<br/>
<i>Then Italic</i> </font>" +
"<br/> <font color=\"green\" >this is simple sentence </font>" +
"<br/> <font face=\"verdana\" >this is simple sentence </font>"+
"<br/><br/><br/><br/><a>this is simple sentence</a>";
Spanned strHtml= Html.fromHtml(str);
TextView tv = (TextView)findViewById(R.id.textView);
tv.setText(strHtml);
我知道的事情,但我的問題是如何做到這一點的string.xml文件 – AndroidDev
這是不可能的。在textviews上設置字體 – Kuffs