2012-12-19 40 views
0

我試圖設置一個段落的標題爲斜體(如果可能的話,也是粗體),但是我不喜歡它。 這是我到目前爲止有:在textview中添加字體到一個特定的單詞

...sound and active.\n\n HEAD \n The skull is broad and... 

所以我想要做的就是設置「HEAD」,以斜體和大膽。

完整代碼:

FlowTextView tv1 = (FlowTextView) findViewById(R.id.tv4);    
    Spanned spannable1 = Html.fromHtml("<html ... </html>"); 
    tv1.setText(spannable1); // using html 
    tv1.setText("...sound and active.\n\n HEAD \n The skull is broad and.... 
    tv1.setTextSize(20); 
    tv1.invalidate(); 

誰能幫助我?

回答

1

嘗試爲:

FlowTextView tv1 = (FlowTextView) findViewById(R.id.tv4);    
     Spanned spannable1 = Html.fromHtml("<html ... </html>"); 
    tv1.setText(spannable1); // using html 
    tv1.setText(Html.fromHtml("...sound and active.\n\n <b> <i>HEAD </i></b> \n 
              The skull is broad and.... ")); 
     tv1.setTextSize(20); 
     tv1.invalidate(); 
0

strings.xml與所需的屬性, 創建您的文字是這樣

<string name="text">This is <b><i> StackOverflow </i></b></string> 

調用此字符串在你的活動這樣

tv.settext(R.string.text); 
0

嘗試此代碼

的strings.xml

<string name="text"> <b> Head </b> \n\n The skull is broad and </string> 

main.xml中

<TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/text" 
     android:textSize="16dp" /> 
0

嘗試在你的TextView標籤使用android:textStyle="italic"。它會正常工作。

0

您可以使用像這樣.. TextView tv = new TextView(this); tv.setTypeface(null,Typeface.ITALIC);

相關問題