Android字体、字重
生活随笔
收集整理的這篇文章主要介紹了
Android字体、字重
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一 設置字體樣式的四個屬性
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.xmlframeworks/base/graphics/java/android/graphics/fonts/SystemFonts.java中在讀取解析這些文件2. fontFamily,typeface區別 --未驗證android:typeface屬性是增加API1android:fontFamily在API16(4.1)中添加了屬性當同時設置typeface和fontFamily時,只有fontFamily生效,typeface有廢棄趨勢?3. 黑體,指的是無襯線字體,在中文中沒有襯線的字體通常稱為黑體,這時這個詞的范疇和無襯線字體(Sans-serif)是類似的。所以在中文字體中常用“黑體”,在西文中常用“無襯線體”的稱呼。而宋體就可以被稱作襯線字體。參考 https://baike.baidu.com/item/%E9%BB%91%E4%BD%93/10402#viewPageContentTextView的默認字體參考第五段三 字重
字重,是指字體的粗細程度,大致分類如下100——淡體 Thin/Hairline200——特細 Extra-Light/Ultra-Light300——細體 Light350——次細 Demi-Light400——標準 Regular/Normal/Book/Plain500——適中 Medium600——次粗 Demi-Bold/Semi-Bold700——粗體 Bold800——特粗 Extra-bold/Extra900——濃體 Black/Heavy950——特濃 Extra-Black/Ultra-BlackAndroid中可以通過textStyle、textFontWeight屬性去設置android:textStyle="normal" //字重400android:textStyle="bold|italic" //字重700 斜體android:textFontWeight="500" //字重500TextView的默認字重參考第五段四 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總結
以上是生活随笔為你收集整理的Android字体、字重的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AltiumDesigner多通道复用设
- 下一篇: bean json转kotlin_And