How can i create font family from assets folder?

android set font family programmatically
android font family list
how to get font from assets folder in android
textview font from assets
android typeface
font in xml
android custom font textview
xml font-style

I want load my fonts from assets folder to my font resource xml file

In fact, I want something like @asset for load it.


<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="">
        android:font="@asset/fontOne/a" />
        android:font="@asset/fontOne/a_italic" />

You need to put .ttf files inside a subfolder in assets folder and then you can load them but I recommend using Calligraphy as it makes everything much easier and cleaner.

Accessing a font under assets folder from XML file in Android, After putting fonts in the assets folder under fonts folder, you can access it in your Create a Typeface object given a family name, and option style information. 2. So I downloaded a family of fonts, which includes different weights, everything from light to extra heavy oblique. Any who, in the font folder instead of stocking up as a family (e.i. Futura>Futura normal, bold, etc.) they just show up as individual files in the folder. Each individual typeface works fine, it's just messy.

If you want to set your font to all texts, use caligraphy library. And if you want to set your font to specific text, use TypeFace instead.

Fonts in XML, One would also need to have the font file placed in the assets folder. Create a font-family XML file: You can create font families which contain  To create a new font family you need to create a new XML font resource. The benefit is that you can access it as a single unit instead of referencing individual font files for each style and weight. To create a font-family, right click on res/font and choose New -> Font Resource File and give any name. In my case, I am using my_custom_font.xml.

You can build your own font class

final class FontsOverride {

    static void setDefaultFont(Context context,
                               String staticTypefaceFieldName, String fontAssetName) {
        final Typeface regular = Typeface.createFromAsset(context.getAssets(),
        replaceFont(staticTypefaceFieldName, regular);

    private static void replaceFont(String staticTypefaceFieldName,
                                    final Typeface newTypeface) {
        try {
            final Field staticField = Typeface.class
            staticField.set(null, newTypeface);
        } catch (NoSuchFieldException e) {
        } catch (IllegalAccessException e) {

and inside your Application Class

    public void onCreate() {

        FontsOverride.setDefaultFont(this, "SERIF", "fontOne/a.ttf");

And inisde your style

    <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:textColorHint">@color/main_color</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:typeface">serif</item>

Android - Custom Fonts, create-assets-folder. Next, right click on the newly-created assets folder and click New > Directory. Name this directory fonts. (If the font you downloaded has a  flutter: fonts: - family: CryptoFont fonts: - asset: font/cryptofont-webfont.ttf By listing the font as an asset in pubspec.yaml , it still gets included in the assets bundle, and thus will be

Using Custom and Downloadable Fonts in Android, So to make the path correct we need to make a slight update and replace src:url() with src:font-url() . Our Sass file would look like: @font-face { font-family:'icofonts';​  When saving font assets, you have to put them in a specific folder, defined in the settings asset. This will ensure that TextMesh Pro can find them and that they are included in builds. Font Source. You must select a font from which to generate a Text Mesh Pro font asset. The font source is only needed to generate the font asset.

Adding Custom Fonts, We often get asked if it is possible to add a custom font to the theme, the @font-​face { Go to the Assets folder and click Add a new asset. To Create your own font family – Right-click the font folder and go to New > Font resource file. The New Resource File window appears. – Enter the file name, and then click OK.

Custom Web Fonts and the Rails Asset Pipeline · GitHub, So right click the res folder and create a new fonts folder. A font family is essentially a dedicated XML file where you define each version of After putting fonts in the assets folder under fonts folder, you can access it in your  Fonts are a completely different kind of asset than you are assuming., A font is completely system dependant. Before Unity can use that font, windows (your system, not everyone uses a pc) needs to be able to use it, but to create them, you need to find a tool that will make fonts for you.

  • You can use Typeface to to do this
  • @Gourav I want this for xml.…
  • check if the subfolder is supported if not just use it as per the documentation e.g. android:fontFamily="@font/lobster" I am not sure subfolder will give you a good structure to your codebase (if this is your point) as nobody what too many fonts file in their application as it might be a heavy resource.
  • @Killer subfolder only support for assets folder! "@font" not support subfolder. you don't have any other way?
  • @Zardchoobe this approach is not gonna help you! I recommend using the @font/fontName method. But tell me one thing why do you want to do this at all?
  • I want standard way:…
  • Without any libraries
  • I want standard way: I want standard way:…
  • Without any libraries