How can I change the NavigationView's item text size?

后端 未结 10 1044
面向向阳花
面向向阳花 2020-12-02 07:32

Google recently released the android.support.design.widget.NavigationView widget as part of the com.android.support:design:22.2.0 library, which gr

相关标签:
10条回答
  • 2020-12-02 08:16

    Goto activity_main.xml and select nav_view in design and you can change menu item text size by updating itemTextAppearance and itemTextColor like as follows

    0 讨论(0)
  • 2020-12-02 08:18

    This worked for me:

    activity_main.xml

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:theme="@style/NavigationDrawerStyle"
        app:headerLayout="@layout/navdrawer_header"
        app:menu="@menu/navdrawer_menu" />
    

    styles.xml

    <style name="NavigationDrawerStyle">
        <item name="android:textSize">16sp</item>
    </style>
    
    0 讨论(0)
  • 2020-12-02 08:20

    You can customize everything from text color to size and font in your style.xml

    <style name="NavDrawerTextStyle" parent="Base.TextAppearance.AppCompat">
        <item name="android:textColor">@color/colorPrimaryDark</item>
        <item name="android:textSize">16sp</item>
        <item name="android:textStyle">bold</item>
    </style>
    

    and then in your NavigationView:

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    
    <android.support.design.widget.NavigationView
        ...
        android:itemTextAppearance="@style/NavDrawerTextStyle"
         />
    

    0 讨论(0)
  • 2020-12-02 08:21

    Scouring through the source code I found this layout file

    /platform/frameworks/support/.../design/res/layout/design_drawer_item.xml

    with the following attribute

    <android.support.design.internal.NavigationMenuItemView
        ...
        android:textAppearance="?attr/textAppearanceListItem"
    

    Which meant all we had to do was to override the textAppearanceListItem style in our project.


    res/values/styles.xml

    <style name="AppTheme" ... >
        ...
        <item name="textAppearanceListItem">@style/list_item_appearance</item>
    </style>
    
    <style name="list_item_appearance">
        <item name="android:textSize">14sp</item>
        <item name="android:fontFamily">sans-serif-medium</item>
    </style>
    

    I'm not totally sure what else this will affect but if anyone has a better answer I'd be happy to accept that instead!

    0 讨论(0)
提交回复
热议问题