问题描述
如今,我经常听到这样的声音:"Roboto是默认字体类型".但是,如何使用此默认字体类型?我的意思是说,在过去我用来下载资产等的过去,我不得不指定诸如此类的内容
I hear it often nowadays: "Roboto is the default font type". But how do I use this default font type? What I mean specifically is that in the old days when I used to download the assets, etc., I used to have to specify things like
<item name="typeface">roboto_bold</item>
想象一下,我有兴趣轮流使用所有话语
Imagine I am interested in using all of say (in turn)
roboto_thin
roboto_thin_italic
roboto_light
roboto_light_italic
roboto_regular
roboto_italic
roboto_medium
roboto_medium_italic
roboto_bold
roboto_bold_italic
roboto_black
roboto_black_italic
roboto_condensed_light
roboto_condensed_light_italic
roboto_condensed_regular
roboto_condensed_italic
roboto_condensed_bold
roboto_condensed_bold_italic
roboto_slab_thin
roboto_slab_light
roboto_slab_regular
roboto_slab_bold
如何在xml布局文件或style.xml
文件中指定它们?
How do I specify them in my xml layout file or style.xml
file?
推荐答案
我已经找到了一些可能性
I've already found some possibilities
最简单的方法是将fontFamily
属性添加到特定的view
中,例如TextView
The simplest way would be add fontFamily
attribute to your specific view
like TextView
根据如何在Android中更改TextView的fontFamily
android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)
http://developer.android.com/reference/android/widget/TextView.html#attr_android:typeface
结合
android:textStyle="normal|bold|italic"
这14种变体是可能的:
this 14 variants are possible:
- 常规机器人
- 斜体字
- Roboto粗体
- Roboto粗体斜体
- 轻巧机器人
- 浅蓝色斜体
- 薄薄的机器人
- 细斜体
- 浓缩机器人
- 自动加粗斜体
- Roboto压缩粗体
- Roboto压缩的粗体斜体
- 机器人中等
- Roboto-Metal italic
- Roboto regular
- Roboto italic
- Roboto bold
- Roboto bold italic
- Roboto-Light
- Roboto-Light italic
- Roboto-Thin
- Roboto-Thin italic
- Roboto-Condensed
- Roboto-Condensed italic
- Roboto-Condensed bold
- Roboto-Condensed bold italic
- Roboto-Medium
- Roboto-Medium italic
您还可以使用以下代码以编程方式执行此操作:
You can also do this programmatically using code as below:
textView.setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL));
使用typeface
可用的内置ibn字体为:
Using typeface
Available built-ibn fonts are:
- 正常
- sans
- serif
- 等宽
您可以像下面这样结合它们:
You can cobine them like below:
android:typeface="sans" | "serif" | "monospace"
请参见 android:type .
您可以像这样在styles.xml`中设置样式:
You set style in styles.xml` like that:
<style name="boldText">
<item name="android:textStyle">bold|italic</item>
<item name="android:textColor">#FFFFFF</item>
</style>
并在main.xml
布局文件中使用此样式,只需使用:
and to use this style in main.xml
layout file just use:
style="@style/boldText"
合并文本属性
您可以像下面的代码中那样混合使用TextView
属性:
android:fontFamily="serif"
android:textStyle="italic"
使用第三方库
Foundry
-通过XML布局和样式应用自定义字体.
Using third-party libraries
Foundry
- apply custom typefaces through XML layouts and styles.
android-typeface-helper
-适用于Android的字体助手
android-typeface-helper
- Typeface helper for Android
您可能还想阅读有关 Roboto
字体和印刷术 Google的设计指南.
You may also want to read about Roboto
typeface and Typography Google's Design Guide.
- Using Roboto thin or condensed
- How do I specify eg. Roboto-Medium or Roboto-Black in styles.xml
Use Roboto font in app with minimum API level 14
希望有帮助
这篇关于如何在XML布局中使用Roboto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!