安卓斜体字[英] android italic typeface

本文是小编为大家收集整理的关于安卓斜体字的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我尝试在文本视图中显示斜体文本. 我使用Method typeface.defaultfromstyle(typeface.italic),但它不起作用,文本的样式未设置为斜体. 如果我在返回DefaultFromStyle()返回时调用GetStyle()方法,则返回0. 有什么想法吗?

推荐答案

Java代码或android:textStyle使用setTypeface(Typeface)从XML布局中使用.如果您希望所有文本都是斜体的,他们应该做到这一点.

编辑: 在这种情况下,默认情况下,我认为您的字体没有斜体样式.从setTypeface(Typeface)方法的文档中:

设置了应显示文本的字体和样式.请注意,并非所有字体家庭实际上都有大胆和斜体变体,因此您可能需要使用setTypeface(Typeface, int)来获取实际想要的外观.

您使用自定义字体吗?尝试

mTextView.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC)

其他推荐答案

这应该全部:

   textView.setTypeface(null, Typeface.BOLD_ITALIC);
   textView.setTypeface(null, Typeface.BOLD);
   textView.setTypeface(null, Typeface.ITALIC);

其他推荐答案

来自TextView的文档...

public void settypeface(字体TF,int样式) 自从:API级别1

设置应显示文本的字体和样式,如果您提供的字体没有所有样式中的所有位,则 在油漆中打开伪造的粗体和斜体钻头.您指定.

本文地址:https://www.itbaoku.cn/post/102757.html

问题描述

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 ?

推荐答案

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)

其他推荐答案

This should be all:

   textView.setTypeface(null, Typeface.BOLD_ITALIC);
   textView.setTypeface(null, Typeface.BOLD);
   textView.setTypeface(null, 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.