How to change the size of menu item icon in NavigationView?

前端 未结 5 981
无人及你
无人及你 2020-12-25 10:21

I have the following menu item:


   
            


        
相关标签:
5条回答
  • 2020-12-25 10:49

    In your xml file the shortest way is there is a property in NavigationView Just add it .

    app:itemIconSize="12dp"

    0 讨论(0)
  • 2020-12-25 10:55

    You can change the size of navigationView icon by overriding design_navigation_icon_size attribute. You can put it in dimens and because you're overriding a private attribute, you need to include tools:override="true"

    <dimen name="design_navigation_icon_size" tools:override="true">40dp</dimen>
    
    0 讨论(0)
  • 2020-12-25 10:58

    The main thing that decide the icon's size is the dimension:navigation_icon_size, have a look at the NavigationMenuItemView class:

     public NavigationMenuItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mIconSize = context.getResources().getDimensionPixelSize(dimen.navigation_icon_size);
    }
    

    so, we can just overide the property in our dimens file.

    For example:

    <dimen name="navigation_icon_size">48dp</dimen>
    

    add that code in the dimens file, and you can find it's size changed.

    Before:

    After:

    0 讨论(0)
  • 2020-12-25 11:09

    According to the the design document set by Google itself, icons should be set to 14sp. I suggest you abide by this recommendation, since this is a standard used throughout all apps. As you said, there are no apps which have large icons in the navigation drawer, as this is not the norm when developing a navigation drawer icon.

    0 讨论(0)
  • 2020-12-25 11:11

    Got Solution

    Make Below entry in dimens.

    <dimen name="design_navigation_icon_size">48dp</dimen>
    
    0 讨论(0)
提交回复
热议问题