相关文章推荐
玩足球的饭卡  ·  Exception in thread ...·  2 年前    · 
冷静的围巾  ·  Android 耳返实践 OpenSL ...·  3 年前    · 
个性的上铺  ·  HttpMediaTypeNotAccept ...·  3 年前    · 

一 设置字体样式的四个属性

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属性(前者可以设置除加粗字重外,还可以设置斜体之类样式)

二 字体、黑体

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的默认字体参考第五段         
字重,是指字体的粗细程度,大致分类如下
    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的默认字重参考第五段    

四 UI口中的“中黑体”

字重500的黑体

五 TextView的默认字体、字重

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>

六 其他参考

谷歌字体文档 https://developer.android.google.cn/guide/topics/resources/font-resource
				
所有图左边是原图,右边是设置了属性后的图,括号末尾是设置的参数 文字大小:18dp 1、android:letterSpacing(字母之间的间距,横向,android:letterSpacing="-0.05") 2、android:lineHeight(每行显示高度,android:lineHeight=“15dp”) 3、android:lineSpacingExtra(文本行之间的额外行间距,android:lineSpacingExtra="-5dp") 4、android:li
使用 Material 主题 (Theming) 自定义 Material 组件,目的是让组件观感与品牌保持一致。Material 主题包括 颜色、字体 和 形状 参数,您可以对这些参数进行调整来获得近乎无限的组件变体,同时保持其核心结构和易用性。 自版本 1.1.0 开始,您可以在 Android 中使用 Material 组件 (Material Design Components, MDC) 库 来实现 Material 主题。如果您要从设计支持库 (Design Support Library).
链接:https://www.zhihu.com/question/263533998/answer/270170059 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 font-weight的实际效果取决于浏览器的处理以及字体自身对粗体细体的支持,按照标准,如果设置的是数字,比如100,200,那么其实100-400都是normal,500~700都是bold,建议直接用lighter,normal,bold,bolder来设置font-weight。前面说
关于安卓字体,ui的设计稿上是不是经常出现,这样的 字重 Medium, 但是textview 中找了半天也没有啊,于是打开百度,面向百度编程。 找了一些字体,直接贴代码吧,xml文件,直接复制过去,就能有明显的对比。 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://sch
文章目录AndroidTextView字体加粗小技巧 AndroidTextView字体加粗小技巧 开发中经常会遇到字体加粗的需求,在使用系统字体的情况下,我们一般是通过在布局文件中给TextView设置android:textStyle="bold"属性。 如果你们的设计师小姐姐不想使用Android的这种加粗效果,只是想要接近于PingFang SC Medium的效果,那么TextVie...
org.greenrobot.eventbus.EventBusException: Subscriber class already registered to event class 15172
org.greenrobot.eventbus.EventBusException: Subscriber class already registered to event class 别说我太单纯: 收藏了.2020.6.5