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 CheckBox
s and Switch
s but it's not working either. How can i fix it?
If you want to style particular checkbox then create your own style and extend it to @style/Widget. AppCompat. CompoundButton. CheckBox .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With