1

I've successfully set up app-wide custom font with the help of Docs and this answer. Basically I've made a new font style and referenced it in my AppTheme:

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    ...
    <item name="android:fontFamily">@font/custom_font</item>
    <item name="fontFamily">@font/custom_font</item> 
</style>

It is working, but not for Switch element labels. As user lxx noted in the linked answer:

This doesn't set the font everywhere... e.g. if you have styles that derive from Base.TextAppearance.AppCompat, it's not used there.

I am not sure though this is the reason behind Switches not having custom fonts.

So how do I apply this custom font to Switch elements too?

enter image description here

c0dehunter
  • 6,412
  • 16
  • 77
  • 139

2 Answers2

3

Set the typeface of switch as below:

switchObj.setSwitchTypeface(Typeface.createFromAsset(mContext.getAssets(), "custom_font.ttf"));
Rutvik Bhatt
  • 3,185
  • 1
  • 16
  • 28
0

for switch label text and XML type of font family: switch_view.setTypeface(ResourcesCompat.getFont(context, font_resource_id));

note: font_resource_id = R.font_directory.font_file

Jason Yeung
  • 81
  • 2
  • 5