700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > android字体斜体代码 Android设置Roboto字体用粗体 斜体 常规 …(类似于自定义字体系列)...

android字体斜体代码 Android设置Roboto字体用粗体 斜体 常规 …(类似于自定义字体系列)...

时间:2020-07-14 10:06:29

相关推荐

android字体斜体代码 Android设置Roboto字体用粗体 斜体 常规 …(类似于自定义字体系列)...

我知道在Android应用程序中以编程方式设置自定义字体.

有没有办法为自定义字体(资产)加载字体,Android框架将使用基于粗体,斜体等的正确文件?

例如,现在我正在尝试将Roboto字体设置为某些TextView

Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Roboto/Roboto-Regular.ttf");

textView.setTypeface(typeface);

它工作正常.但由于我将xml布局中的TextView设置为粗体,因此文本不会加粗

android:id="@+id/my_id"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="20dp"

android:layout_marginRight="20dp"

android:layout_marginTop="50dp"

android:textStyle="bold"

android:gravity="center"

android:text="@string/my_text"

android:textColor="@color/my_foreground"

android:textSize="24dp" />

如何从资产中正确加载字体,这将起作用?

textView.setTypeface(typeface, Typeface.BOLD);

在我的资产目录中,只有一个“字体系列”

Roboto-Black.ttf

Roboto-BlackItalic.ttf

Roboto-Bold.ttf

Roboto-BoldCondensed.ttf

Roboto-BoldCondensedItalic.ttf

Roboto-BoldItalic.ttf

Roboto-Condensed.ttf

Roboto-CondensedItalic.ttf

Roboto-Italic.ttf

Roboto-Light.ttf

Roboto-LightItalic.ttf

Roboto-Medium.ttf

Roboto-MediumItalic.ttf

Roboto-Regular.ttf

Roboto-Thin.ttf

Roboto-ThinItalic.ttf

如何在一个字体/系列中加载所有字体?

解决方法:

标签:android,fonts,typeface,font-family

来源: https://codeday.me/bug/0621/1250873.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。