question

njsokalski avatar image
0 Votes"
njsokalski asked JarvanZhang-MSFT edited

Customizing Menu Items in NavigationView

I have a com.google.android.material.navigation.NavigationView that contains menu items from an xml file. This works fine, except that the item text looks very ugly (most importantly the size). I'm not sure where to specify things like this for the menu items. I found app:itemTextColor as an attribute of the NavigationView, but I'm sure there must be more I can do for settings things like size, font family, etc. I would prefer to specify this in xml, but I can handle doing it in code if necessary. Is there a way to give more customization to the Menu Items? Thanks.

dotnet-android
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT edited

Hello njsokalski,​

Welcome to our Microsoft Q&A platform!

I can do for settings things like size, font family, etc.

To change the fontsize of the item's text, try customing a textView style and consuming it for app:itemTextAppearance property. Here is the sample code, you could refer to it.

<com.google.android.material.navigation.NavigationView
    ...
    app:itemTextColor="#00ff00"
    app:itemTextAppearance="@style/CustomTextStyle"/>

<!--styles.xml-->
<style name="CustomTextStyle" parent="android:Widget.TextView">
  <item name="android:fontFamily">@font/sans-serif-smallcaps</item>
  <item name="android:textSize">20sp</item>
</style>


Best Regards,

Jarvan Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.