How to use specified weights for fonts in XML

后端 未结 9 2004
小蘑菇
小蘑菇 2021-01-30 02:58

Using the Fonts in XML feature you can specify various font weights for a font family. For example:



        
9条回答
  •  长发绾君心
    2021-01-30 03:35

    I struggled with several weights of a font: bold, semibold, medium, regular. For me it finally worked when I created a .xml file for each weight, with normal and italic, and then referencing them in the layout or style with both android:fontFamily: and fontFamily:. The latter was important, cause otherwise it would only work in very high API levels.

        
    
    
        
        
         
    
    
    
         
    

    This works even in Android 5.0, didn't test it for lower ones.

    So basically create a font.xml file for each font weight, use both app: and android: prefixes, and then reference them with both prefixes.

提交回复
热议问题