You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library overrides/ignores the theme's android:fontFamily, making it more difficult than it should be to use custom font families in an app using the library.
My app (https://pachli.app) allows the user to set a custom font. This is achieved by providing a number of different styles that override android:fontFamily, and applying the correct style at runtime based on the value of a user's preference.
val fontFamily =EmbeddedFontFamily.from(sharedPreferencesRepository.getString(PrefKeys.FONT_FAMILY, "default"))
if (fontFamily !==EmbeddedFontFamily.DEFAULT) {
getTheme().applyStyle(fontFamily.style, true)
}
This works everywhere except menu items.
For that I have to do this workaround after the menu is modified.
/** * Sets the correct typeface for everything in the drawer. * * The drawer library forces the `android:fontFamily` attribute, overriding the value in the * theme. Force-ably set the typeface for everything in the drawer if using a non-default font.*/privatefunupdateMainDrawerTypeface(fontFamily:EmbeddedFontFamily) {
if (fontFamily ==EmbeddedFontFamily.DEFAULT) returnval typeface =ResourcesCompat.getFont(this, fontFamily.font) ?:returnfor (i in0..binding.mainDrawer.adapter.itemCount) {
val item = binding.mainDrawer.adapter.getItem(i)
if (item !isTypefaceable) continue
item.typeface = typeface
}
}
(EmbeddedFontFamily is an enum with properties for the font resource and style resource).
Since the code only seems to use sans-serif and sans-serif-medium I think you might get the effect you want by (untested):
About this issue
The library overrides/ignores the theme's
android:fontFamily
, making it more difficult than it should be to use custom font families in an app using the library.My app (https://pachli.app) allows the user to set a custom font. This is achieved by providing a number of different styles that override
android:fontFamily
, and applying the correct style at runtime based on the value of a user's preference.For example, in
styles.xml
:and in a base
Activity.onCreate()
:This works everywhere except menu items.
For that I have to do this workaround after the menu is modified.
(
EmbeddedFontFamily
is an enum with properties for the font resource and style resource).Since the code only seems to use
sans-serif
andsans-serif-medium
I think you might get the effect you want by (untested):android:fontFamily="sans-serif"
everywhere.android:fontFamily="sans-serif-medium"
withandroid:textFontWeight="500"
, as "500" is the "medium" font weight.Details
Checklist
The text was updated successfully, but these errors were encountered: