How do I specify eg. Roboto-Medium or Roboto-Black in styles.xml

前端 未结 4 1160
忘了有多久
忘了有多久 2021-01-30 03:24

Posts like this How to change fontFamily of TextView in Android suggests, that the variants of Roboto fonts you can specify in styles.xml in Android 4.2 boils down to the follow

4条回答
  •  爱一瞬间的悲伤
    2021-01-30 03:47

    Support Library 26 introduced using fonts in XML, and it's backwards compatible to Android API 14.

    To add fonts as resources, perform the following steps in the Android Studio:

    1. Right-click the res folder and go to New > Android resource directory. The New Resource Directory window appears.

    2. In the Resource type list, select font, and then click OK. Note: The name of the resource directory must be font.

    1. Add your font files in the font folder. The folder structure below generates R.font.dancing_script, R.font.lobster, and R.font.typo_graphica.

    1. Double-click a font file to preview the file's fonts in the editor.

    To set a font for the TextView, in the layout XML file, set the fontFamily attribute to the font file you want to access.

    
    

    The Android Studio layout preview allows you to preview the font set in the TextView.

    To add a font to a style, Open the styles.xml, and set the fontFamily attribute to the font file you want to access.