Font is not applying on CheckBox and Switch Android Studio 3

Amir_P :

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?

Daniel Zolnai :

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: https://issuetracker.google.com/issues/63250768

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=428896&siteId=1