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. I
This should be all:
textView.setTypeface(null, Typeface.BOLD_ITALIC);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
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)
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.