Define a font for each flavor on Android Studio

Viewed 39

I've encouter a very weird behaviour on Android Studio and hope find the answer.
So let's say I have 10 TextViews, each one declared with one of two types :

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/title"
    android:fontFamily="@font/first_font"/>

and

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/some_details"
    android:fontFamily="@font/second_font"/>

where I've defined the "first_font" and "second_font" on a resource file (I don't know if it is a correct way) through

<font name="first_font">@font/real_font_name_file_1.otf</font>
<font name="second_font">@font/real_font_name_file_2.otf</font>

The purpose of that, so I can easily redefine them by flavor. So the flavor will override the "main" one.
Even it seems a little weird, it is working perfectly without any error like this.

Except when it comes to use the handle-system font (for example sans-serif or sans-serif-light), when I try to put :

<font name="first_font">sans-serif</font>

I have this error while compiling files project : failed to compile value files

I eventually tried to define them a string, work for both cases, but I keep having a warning unexpected resource type string, expected font

So my question : Is there a cleanest way to handle the fonts by flavors by just changing a value on a file ?

Thanks.

0 Answers
Related