0

Project with MDC doesn't follow the fontFamily I set in Headline 6 in my theme when on dark theme. I used metropolis_500 as my fontFamily in my Headline 6 style. It shows up normally on Light Theme but not on Dark Theme.

implementation 'com.google.android.material:material:1.1.0'

<!--Base Theme-->
<style name="Base.Theme.MyApp" parent="Base.Theme.MaterialThemeBuilder">
    ...
    <item name="textAppearanceHeadline6">@style/TextAppearance.MyTheme.Headline6</item>
    <item name="toolbarStyle">@style/Widget.MyTheme.Toolbar.AppBar</item>
    ...
</style>

<!--AppBar Style-->
<style name="Widget.MyTheme.Toolbar.AppBar" parent="Widget.MaterialComponents.Toolbar.Surface">
    <item name="android:background">?attr/colorAppBar</item>
    <item name="titleTextColor">?colorOnAppBar</item>
</style>

<!--Headline 6-->
    <style name="TextAppearance.MyTheme.Headline6" parent="TextAppearance.MaterialComponents.Headline6">
    <item name="fontFamily">@font/metropolis_500</item>
</style>

I tried explicitly specifying the use of Headline 6 in my AppBar Style and did not work.

<!--AppBar Style-->
<style name="Widget.MyTheme.Toolbar.AppBar" parent="Widget.MaterialComponents.Toolbar.Surface">
    <item name="android:background">?attr/colorAppBar</item>
    <item name="titleTextColor">?colorOnAppBar</item>
    <item name="titleTextAppearance">@style/TextAppearance.MyTheme.Headline6</item>
</style>

I also tried explicitly specifying the toolbarStyle on Dark Theme Style.

<style name="Theme.MyApp" parent="Base.Theme.MyApp">
    ...
    <item name="toolbarStyle">@style/Widget.MyTheme.Toolbar.AppBar</item>
</style>

I also tried reverting to the default Material Components toolbarStyle.

<item name="toolbarStyle">@style/Widget.MaterialComponents.Toolbar.Surface</item>

What the text appearance of the toolbar supposed to be

What instead looked like in Dark Theme

Nothing worked. Light theme is alright, but dark theme isn't. The metropolis font shows up properly on other parts in dark theme like in TextViews that use the Headline 6 style.

hamthenormal
  • 856
  • 8
  • 21
  • 1
    I have run into this same issue. I noticed colorPrimary value isn't applied to the app bar background (https://stackoverflow.com/questions/58363200/actionbar-background-with-materialcomponents-theme). Perhaps this is related. – Eric Williams Mar 17 '21 at 23:51
  • @EricWilliams, I just posted a possible solution to your problem. Hope it helps. Cheers. – hamthenormal Mar 19 '21 at 00:33

0 Answers0