Reputation: 26478
I try to display italic text in a textview. I use the method TypeFace.defaultFromstyle(TypeFace.ITALIC) but it doesn't work, the style of the text is not set to italic. If i call the getStyle() method on the return of defaultFromstyle() it returns 0. Any idea ?
Upvotes: 1
Views: 17489
Reputation: 2245
This should be all:
textView.setTypeface(null, Typeface.BOLD_ITALIC);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
Upvotes: 2
Reputation: 841
From the docs on TextView ...
public void setTypeface (Typeface tf, int style) Since: API Level 1
Sets the typeface and style in which the text should be displayed, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.
Upvotes: 1
Reputation: 16357
Use setTypeface(Typeface)
from the Java code or android:textStyle
from the XML layout. They should do the trick, if you want all your text to be italic.
Edit:
In that case, I would think that your font doesn't have italic style, by default. From the documentation of the setTypeface(Typeface)
method:
Sets the typeface and style in which the text should be displayed. Note that not all Typeface families actually have bold and italic variants, so you may need to use setTypeface(Typeface, int)
to get the appearance that you actually want.
Do you use custom font? Try
mTextView.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC)
Upvotes: 20