Switching locale does not change font style in app, although language is being changed

Viewed 134

I want to implement custom font style based on locale in my android app. I have created different font folders for different locales, font-en, font-hi, etc and placed the relevant xml files in that. When the app is loaded the fonts are displayed as per selected locale. But when user switches locale from within the app, font style is not changed. Although the language is changed properly. I have to re-start my app to apply the font style for the changed locale.

Can anybody help me with this. Why changing the locale does not change font style, although the language is being changed correctly.

1 Answers

create a font.xml file inside Values directory for each Locale like this

font.xml (English)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <font name="appFontRegular">@font/poppins_regular</font>
    <font name="appFontBold">@font/poppins_bold</font>
</resources>

font.xml (arabic)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <font name="appFontRegular">@font/helvetica_neue_lt_arabic_55_roman</font>
    <font name="appFontBold">@font/helvetica_neue_lt_arabic_75_bold</font>
</resources>
Related