I'm using Android Studio and have a SwitchCompat widget in my main activity. The default fontfamily it had was sans-serif-medium and I changed it to quicksand_light. I also have some TextViews with each of their fontfamily's set to quicksand_light. On the design tab of the xml file for my activity it shows the SwitchCompat having the quicksand_light fontfamily just as the TextViews, but when I run it on my phone or on an emulator the SwitchCompat's fontfamily is sans-serif-medium. Is there something extra I need to do to change the fontfamily or is this a bug or is this just me?
I haven't dived deep into why it's not working correctly when defining the fontFamily
attribute in xml, but IT WORKS if you set the typeface programmatically.
Here's an example using data-binding.
Add the following data-binding adapter:
@BindingAdapter("labelTypeface")
fun setLabelTypeface(view: SwitchCompat, @FontRes id: Int) {
view.typeface = ResourcesCompat.getFont(view.context, id)
}
and use it in your layout:
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:labelTypeface="@{R.font.stratum}"
... />
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