Thursday, March 22, 2018

fonts - Valid values for android:fontFamily and what they map to?



In the answer to this question the user lists values for android:fontFamily and 12 variants (see below). Where do these values come from? The documentation for android:fontFamily does not list this information in any place (I checked here, and here). The strings are listed in the Android styles.xml file in various places, but how do these map back to the Roboto font?




From android 4.1 / 4.2, the following Roboto font families are
available:



android:fontFamily="sans-serif"           // roboto regular  
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)


in combination with this



android:textStyle="normal|bold|italic" 


12 variants are possible:




  • Regular

  • Italic

  • Bold

  • Bold-italic

  • Light

  • Light-italic

  • Thin

  • Thin-italic

  • Condensed regular

  • Condensed italic

  • Condensed bold

  • Condensed bold-italic




In the styles.xml file in the application I'm working on somebody listed this as the font family, and I'm pretty sure it's wrong:



Roboto-Regular.ttf



I'd like to get the theme for our app set up correctly (which includes using fontFamily correctly) and remove all the redundancy that is in some of the styles that were created before I had a look at the file.


Answer




Where do these values come from? The documentation for android:fontFamily does not list this information in any place




These are indeed not listed in the documentation. But they are mentioned here under the section 'Font families'. The document lists every new public API for Android Jelly Bean 4.1.




In the styles.xml file in the application I'm working on somebody listed this as the font family, and I'm pretty sure it's wrong:




Yes, that's wrong. You don't reference the font file, you have to use the font name mentioned in the linked document above. In this case it should have been this:



sans-serif


Like the linked answer already stated, 12 variants are possible:



Added in Android Jelly Bean (4.1) - API 16 :



Regular (default):



sans-serif
normal


Italic:



sans-serif
italic


Bold:



sans-serif
bold


Bold-italic:



sans-serif
bold|italic


Light:



sans-serif-light
normal


Light-italic:



sans-serif-light
italic


Thin :



sans-serif-thin
normal


Thin-italic :



sans-serif-thin
italic


Condensed regular:



sans-serif-condensed
normal


Condensed italic:



sans-serif-condensed
italic


Condensed bold:



sans-serif-condensed
bold


Condensed bold-italic:



sans-serif-condensed
bold|italic


Added in Android Lollipop (v5.0) - API 21 :



Medium:



sans-serif-medium
normal


Medium-italic:



sans-serif-medium
italic


Black:



sans-serif-black
italic


For quick reference, this is how they all look like:




No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...