Closed harounandroid closed 3 years ago
Hey @harounandroid,
Yes, all Labels support custom typefaces (both FabOption
and ExpandableFab
have a Label
, and Label
is derived from TextView
).
Follow this Stack Overflow answer to add a custom typeface to your project, then use the instructions for setting the View programmatically. As of now, you must set the custom typeface programmatically since the library doesn't expose the Label's typeface via XML (though this will be implemented in the next release).
So if you use the same FabOptions in both portrait orientation and landscape orientation, you can easily apply custom typefaces in Kotlin like this:
val expandableFabLayout= view.findViewById<ExpandableFabLayout>(R.id.expandable_fab_layout)
// Use this method if you use the same FabOptions in both portrait orientation and landscape orientation
expandableFabLayout.getCurrentConfiguration().fabOptions.forEach {
it.label.typeface = ResourcesCompat.getFont(requireContext(), R.font.birthstone)
}
// Otherwise, if you use different widgets between portrait and landscape orientations, you have to set them separately
// This call will update all FabOption Label's shown in portrait mode
expandableFabLayout.portraitConfiguration.fabOptions.forEach {
it.label.typeface = ResourcesCompat.getFont(requireContext(), R.font.birthstone)
}
// This call will update all FabOption Label's shown in landscape mode
expandableFabLayout.landscapeConfiguration.fabOptions.forEach {
it.label.typeface = ResourcesCompat.getFont(requireContext(), R.font.birthstone)
}
The ability to set this via XML will be added in the next release. Let me know if you have any questions.
Works , thank you
Hey @harounandroid ,
Good news, starting from v1.2.1**, the ExpandableFab library now lets you set fonts (typefaces) on the labels directly in XML instead of having to set them programmatically in your code. This version also includes other new features and bug fixes.
You can get it by cloning the master branch of this repo, or pulling it from Maven Central. Thanks for using the library!
**EDIT: use v1.2.1 or higher, not v1.2.0 (v1.2.0 contains a bug in the Label class when ran on some older devices).
is FabOption supporting typefaces fot its text ?