本文介绍了安卓斜体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示在一个TextView斜体。我使用的方法TypeFace.defaultFromstyle(TypeFace.ITALIC),但它不工作,该文本的样式未设置为斜体。如果我请defaultFromstyle的回报(的getStyle()方法),则返回0。你知道吗?

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 ?

推荐答案

使用 setTypeface(字体)从Java code或安卓:TEXTSTYLE 从XML布局。他们应该做的伎俩,如果你希望所有的文字是斜体。

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.

编辑:在这种情况下,我会认为你的字体没有斜体,默认情况下。从 setTypeface(字体)方法的文档:

In that case, I would think that your font doesn't have italic style, by default. From the documentation of the setTypeface(Typeface) method:

设置字体和风格,其中的文字应显示。请注意,并非所有字样的家庭确实有粗体和斜体变体,所以你可能需要使用 setTypeface(字体,INT)来得到你真正想要的外观。

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)

这篇关于安卓斜体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 01:15