Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font is not applying on CheckBox and Switch Android Studio 3

Tags:

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?

like image 781
Amir_P Avatar asked Nov 01 '17 20:11

Amir_P


People also ask

Can we apply theme on CheckBox?

If you want to style particular checkbox then create your own style and extend it to @style/Widget. AppCompat. CompoundButton. CheckBox .


1 Answers

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

like image 187
Daniel Zolnai Avatar answered Sep 17 '22 16:09

Daniel Zolnai