Do we need to copy the TTF font every time we want to change the font in the application

Before, in order to make my application work in the Gingerbread device and above, I need to copy the Robotto font resource to the resource folder. This is because Gingerbread does not come with the Robotto font itself.

enter image description here

However, let's say I decided to deploy my application only on a Jelly Bean device.

  • Do I still need to copy font resources to the resource folder manually? Can I use font resources from the system itself? Is this something stimulating? I thought, without supplying my own font files, I can reduce my application.
  • This is the code to get TypeFace from the resource folder.

    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");

    If I want to get TypeFace directly from the system itself, how?

+4
source share
1 answer

The good news is that if you support 4.1, it is simple. Check out this link and scroll down to the fonts for full details, but basically you will have three font families (Roboto, Roboto Light, RobotoCondensed) to choose from and four styles for each (normal, bold, italics, bold italics).

In XML, you can simply use 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 programmatically, you can purchase them like this:

 Typeface robotoLightItalic = Typeface.create("sans-serif-light", Typeface.ITALIC); 
+12
source

Source: https://habr.com/ru/post/1435315/


All Articles