Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the item text size in navigation view

I am creating a navigation drawer in android and I have added the items in menu_main.xml but I am not able to change the size of the menu items. Below is the code menu_main.xml:

  <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
    <item
        android:id="@+id/motel"
        android:title="Motel">
    </item>
    <item
        android:id="@+id/packages"
        android:title="Packages">
    </item>
    </group>
</menu>
like image 366
jobin Avatar asked Oct 15 '15 04:10

jobin


People also ask

Which is the correct syntax to change the font size in Android Studio Mcq?

Click Ctrl + Shift + A. A new box will appear, search font there then you can see a lot of options then click on increase font size. It will increase the font size of the editor by some pixels.


2 Answers

Create a style and apply it to NavigationView using app:theme

<style name="NavigationViewStyle">
     <item name="android:textSize">20sp</item> <!-- menu item text size-->
     <item name="android:listPreferredItemHeightSmall">40dp</item><!-- menu item height-->
</style>

And then as said, apply this style to NavigationView using app:theme

<android.support.design.widget.NavigationView
       ...
       ...    
        app:theme="@style/NavigationViewStyle"
       ...
       ...


</android.support.design.widget.NavigationView>
like image 121
Paresh Mayani Avatar answered Nov 11 '22 23:11

Paresh Mayani


Adding on to Paresh's answer above,

Create your own style "NavigationViewStyle" as stated above

<style name="NavigationViewStyle">
     <item name="android:textSize">20sp</item> 
     <item name="android:listPreferredItemHeightSmall">40dp</item>
</style>

Apply it to your menu items

<android.support.design.widget.NavigationView
        .
        .
        app:itemTextAppearance="@style/NavigationViewStyle"
        . />
like image 21
Actiwitty Avatar answered Nov 11 '22 22:11

Actiwitty