Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 following:

  • Regular
  • Italic
  • Bold
  • Bold-italic
  • Light
  • Light-italic
  • Thin
  • Thin-italic
  • Condensed regular
  • Condensed italic
  • Condensed bold
  • Condensed bold-italic

That leaves out the ability to style TextViews using eg. the Roboto-Medium or Roboto-Black fonts.

But why would Google add system wide fonts that can not be used for styling of your TextViews? Surely there must be some way of specifying all of the Roboto fonts from within styles.xml (ie. NOT having to embed the fonts as Assets and creating custom TextViews in code) - but how?

like image 689
ckibsen Avatar asked Jan 09 '14 14:01

ckibsen


People also ask

What font is close to Roboto medium?

Arial, Helvetica, sans-serif.

What is Roboto font style?

Roboto (/roʊˈbɒt. oʊ/) is a neo-grotesque sans-serif typeface family developed by Google as the system font for its mobile operating system Android, and released in 2011 for Android 4.0 "Ice Cream Sandwich".


1 Answers

On Android 5.0 you can set Roboto Medium with sans-serif-medium.

This solution, taken from Google iosched 2014, uses sans-serif on Android pre-v21:

values/styles.xml

<style name="MyStyle">     <item name="android:fontFamily">@string/font_fontFamily_medium</item> </style> 

values/fonts.xml

<string name="font_fontFamily_medium">sans-serif</string> 

values-v21/fonts.xml

<string name="font_fontFamily_medium">sans-serif-medium</string> 
like image 151
rciovati Avatar answered Oct 23 '22 23:10

rciovati