Previously, to make my app workable in Gingerbread device and above, I have to copy the Robotto font resource into asset folder. This is because Gingerbread doesn't come with Robotto font itself.
However, let say, I decide to deploy my app to Jelly Bean device only.
This is the code to get TypeFace
from asset folder.
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
If I want to get TypeFace
directly from system itself, how?
The good news is, if you're supporting 4.1, it's dead simple. Check out this link and scroll down to fonts for the full details, but basically, you'll have three font families (Roboto, Roboto Light, RobotoCondensed) to choose from, and four styles for each (normal, bold, italic, bold italic).
In XML, you can just use the standard text attributes:
android:fontFamily="sans-serif"
android:fontFamily="sans-serif-light"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:textStyle="italic"
android:textStyle="bold|italic"
Or programatically you can acquire them like so:
Typeface robotoLightItalic = Typeface.create("sans-serif-light", Typeface.ITALIC);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With