Customizing Menu Items in NavigationView

Nathan Sokalski 4,111 Reputation points
2021-10-07T01:03:09.393+00:00

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.

Developer technologies .NET Xamarin
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2021-10-08T02:55:06.667+00:00

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.