Android font, font weight

1. Set four attributes of font style

1. 四个属性:fontFamily,typeface,textStyle,textFontWeight
    <!-- Typeface (normal, sans, serif, monospace) for the text. -->
    <attr name="typeface" />
    <!-- 
        Font family (named by string or as a font resource reference) for the text.
        (casual,cursive,sans-serif-smallcaps,sans-serif-condensed,sans-serif-condensed-light,
        sans-serif-condensed-medium,sans-serif,sans-serif-black,sans-serif-medium,sans-serif-light,
        sans-serif-thin,serif,serif-monospace,monospace) 
    -->
    <attr name="fontFamily" />
    <!-- Weight for the font used in the TextView. -->
    <attr name="textFontWeight" />
    <!-- Style (normal, bold, italic, bold|italic) for the text. -->
    <attr name="textStyle" />
    
2. 设置字体用fontFamily,typeface属性
3. 设置字重用textStyle,textFontWeight属性(前者可以设置除加粗字重外,还可以设置斜体之类样式)

Two fonts, boldface

1. 设置字体用fontFamily,typeface属性,设置fontFamily,typeface时,例:android:fontFamily="sans-serif-medium"
   ,其中sans-serif-medium是实际字体的别名, 字体文件以及别名文件路径如下:
        字体文件位置: /system/fonts/xxx.ttf
        别名文件位置: /system/etc/fonts.xml
   frameworks/base/graphics/java/android/graphics/fonts/SystemFonts.java中在读取解析这些文件
     
2. fontFamily,typeface区别 --未验证
    android:typeface属性是增加API1
    android:fontFamily在API16(4.1)中添加了属性
    当同时设置typeface和fontFamily时,只有fontFamily生效,typeface有废弃趋势?
    
3. 黑体,指的是无衬线字体,在中文中没有衬线的字体通常称为黑体,这时这个词的范畴和无衬线字体(Sans-serif)是类似的。
   所以在中文字体中常用“黑体”,在西文中常用“无衬线体”的称呼。而宋体就可以被称作衬线字体。
   参考 https://baike.baidu.com/item/%E9%BB%91%E4%BD%93/10402#viewPageContent

TextView的默认字体参考第五段         

Three characters are heavy

字重,是指字体的粗细程度,大致分类如下
    100——淡体 Thin/Hairline
    200——特细 Extra-Light/Ultra-Light
    300——细体 Light
    350——次细 Demi-Light
    400——标准 Regular/Normal/Book/Plain
    500——适中 Medium
    600——次粗 Demi-Bold/Semi-Bold
    700——粗体 Bold
    800——特粗 Extra-bold/Extra
    900——浓体 Black/Heavy
    950——特浓 Extra-Black/Ultra-Black
    
Android中可以通过textStyle、textFontWeight属性去设置
        android:textStyle="normal"      //字重400
        android:textStyle="bold|italic" //字重700 斜体
        android:textFontWeight="500"    //字重500
        
TextView的默认字重参考第五段    

"Medium black body" in the mouth of SiUI

字重500的黑体

5. TextView’s default font and weight

TextView默认字体是黑体+400字重,安卓中的黑体(sans-serif)用的是Roboto相关文件:

framework/res/
     <style name="TextAppearance.Material">
         <item name="fontFamily">@string/font_family_body_1_material</item>
              <string name="font_family_body_1_material">sans-serif</string>
              
/system/etc/fonts.xml
   <family name="sans-serif">
        <font weight="100" style="normal">Roboto-Thin.ttf</font>
        <font weight="100" style="italic">Roboto-ThinItalic.ttf</font>
        <font weight="300" style="normal">Roboto-Light.ttf</font>
        <font weight="300" style="italic">Roboto-LightItalic.ttf</font>
        <font weight="400" style="normal">Roboto-Regular.ttf</font>
        <font weight="400" style="italic">Roboto-Italic.ttf</font>
        <font weight="500" style="normal">Roboto-Medium.ttf</font>
        <font weight="500" style="italic">Roboto-MediumItalic.ttf</font>
        <font weight="900" style="normal">Roboto-Black.ttf</font>
        <font weight="900" style="italic">Roboto-BlackItalic.ttf</font>
        <font weight="700" style="normal">Roboto-Bold.ttf</font>
        <font weight="700" style="italic">Roboto-BoldItalic.ttf</font>
    </family>

Six other references

谷歌字体文档 https://developer.android.google.cn/guide/topics/resources/font-resource

Guess you like

Origin blog.csdn.net/yfbdxz/article/details/126350250