java – Font is not applying on CheckBox and Switch Android Studio 3-ThrowExceptions

Exception or error:

After updating to Android Studio 3 and using the latest SDK and build tools there is a feature to add fonts to the fonts folder under resources and use it directly in xml or java. I’m using this code in my theme in styles.xml to apply theme on my whole application

<item name="android:fontFamily">@font/iransansfont</item>

it’s working on Button, TextView, and pretty much everything except CheckBox and Switch widgets. I even tried fontFamily on my CheckBoxs and Switchs but it’s not working either. How can i fix it?

How to solve:

Currently it is not possible to set fonts on CheckBoxes (and some other widgets) with font resources via XML.
You can do it programmatically instead:

checkBox.setTypeface(ResourcesCompat.getFont(context, R.font.your_font));

This issue has been reported on the Android bug tracker, star it to get it fixed soon:

Leave a Reply

Your email address will not be published. Required fields are marked *