material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.43k stars 3.08k forks source link

Font of menu in NavigationView reverted to default font after clicked #3396

Closed RakaDoank closed 1 year ago

RakaDoank commented 1 year ago

Help me, i don't know why this is happened. I didn't make any change even listening to click listener since the android:id attribute is tied/matched with navigation.

The menus text will be reverted to default font again after i clicked a menu.

https://github.com/material-components/material-components-android/assets/23445738/09082cf4-24a3-4d7f-94cd-4ce703823b8b

but, the menus text will showing with correct font again after i switched Light/Dark theme. (sorry for the mosaic)

Here my themes.xml file looks like

<style name="Base.Theme.Kadai" parent="Theme.Material3.DayNight.NoActionBar">
  ..
  <item name="fontFamily">@font/montserrat_medium</item>
  ..
</style>
imhappi commented 1 year ago

Hi @RakaDoank Are you on the latest library version? I'm not able to reproduce this issue

Also, are you using the itemTextAppearance attribute to change the font of the menu items?

RakaDoank commented 1 year ago

@imhappi No, i didn't do "style" at all to the menu items

related dependencies: com.google.android.material:material:1.9.0 androidx.drawerlayout:drawerlayout:1.2.0 androidx.navigation:navigation-fragment-ktx:2.5.3 androidx.navigation:navigation-ui-ktx:2.5.3

imhappi commented 1 year ago

I'm still not able to repro this issue unfortunately, but here are some things that I can potentially think of:

Can you try setting itemTextAppearance to text appearance with the font you are using? Ie.

<style name="foo">
   <item name="fontFamily">@font/montserrat_medium</item>
</style>

and setting itemTextAppearance=@style/foo on the NavigationView; I'm not sure why the text is the correct font initially and changes, but the NavigationView items have their own text appearance specified in the material style.

It could also be related to the font; when a navigation view item is clicked, it changes all of the checked items to bold, and all of the unchecked items to normal. Make sure that there is a normal and bold style available for the font.

RakaDoank commented 1 year ago

Yes finally, thank you. The menus font is never changed anymore, by setting app:itemTextAppearance=@style/Theme.Material3.DayNight.NoActionBar.

It could be also that you mentioned, i checked Navigation drawer specs, and it is correct checked items will be '500' weight. I didn't set definition style for the font weight variants. @font/montserrat_medium i used, it was just a font base.