更改默认导航抽屉的图标大小

时间:2017-01-25 04:44:47

标签: android xml android-layout

尝试更改默认导航栏的图标大小,并在每个项目后添加分隔符,但我不明白如何执行此操作?这是菜单抽屉视图:

<group android:checkableBehavior="single">
    <item
        android:id="@+id/agenda"
        android:icon="@drawable/agenda"
        android:title="AGENDA"
        />
    <item
        android:id="@+id/speakers"
        android:icon="@drawable/speakers"
        android:title="SPEAKERS" />
    <item
        android:id="@+id/schedule"
        android:icon="@drawable/schedule"
        android:title="SCHEDULE" />
    <item
        android:id="@+id/organiser"
        android:icon="@drawable/organiser"
        android:title="ORGANISER" />
    <item
        android:id="@+id/partners"
        android:icon="@drawable/partner"
        android:title="PARTNERS" />
    <item
        android:id="@+id/event_info"
        android:icon="@drawable/eventinfo"
        android:title="EVENT-INFO" />
</group>

这是dimens.xml

<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="nav_header_vertical_spacing">16dp</dimen>
    <dimen name="nav_header_height">160dp</dimen>
</resources>

3 个答案:

答案 0 :(得分:2)

在dimens.xml中设置design_navigation_icon_size和design_navigation_icon_padding对我有用。

/values/dimens.xml

<dimen name="design_navigation_icon_size" tools:override="true">10dp</dimen>
<dimen name="design_navigation_icon_padding" tools:override="true">10dp</dimen>

答案 1 :(得分:0)

尝试使用divider

<group android:checkableBehavior="single">
<item
    android:id="@+id/agenda"
    android:icon="@drawable/agenda"
    android:title="AGENDA"
    />
</group>

<group android:checkableBehavior="single">
<item
    android:id="@+id/speakers"
    android:icon="@drawable/speakers"
    android:title="SPEAKERS" />
</group>

<group android:checkableBehavior="single">
<item
    android:id="@+id/schedule"
    android:icon="@drawable/schedule"
    android:title="SCHEDULE" />
</group>

<group android:checkableBehavior="single">
<item
    android:id="@+id/organiser"
    android:icon="@drawable/organiser"
    android:title="ORGANISER" />
</group>

<group android:checkableBehavior="single">
<item
    android:id="@+id/partners"
    android:icon="@drawable/partner"
    android:title="PARTNERS" />
</group>

<group android:checkableBehavior="single">
<item
    android:id="@+id/event_info"
    android:icon="@drawable/eventinfo"
    android:title="EVENT-INFO" />
</group>

并且对于图标,Icon必须为24dp大小

检查此链接是否有图标大小 https://material.io/guidelines/patterns/navigation-drawer.html#navigation-drawer-specshttps://material.io/guidelines/layout/metrics-keylines.html#metrics-keylines-touch-target-size

答案 2 :(得分:0)

您可以通过覆盖dimens.xml中的design_navigation_icon_size属性来更改导航抽屉图标的大小。

<dimen name="design_navigation_icon_size" tools:override="true">40dp</dimen>

要为每个项目添加分隔符,您应该为每个组项目提供唯一的 id ,如下所示

<group 
      android:id="@+id/group_item_1"
      android:checkableBehavior="single">
 <item
    android:id="@+id/agenda"
    android:icon="@drawable/agenda"
    android:title="AGENDA"/>
 </group> 

 <group 
      android:id="@+id/group_item_2"
      android:checkableBehavior="single">
 <item
    android:id="@+id/speakers"
    android:icon="@drawable/speakers"
    android:title="SPEAKERS" />
 </group> 

 <group 
      android:id="@+id/group_item_3"
      android:checkableBehavior="single">
 <item
    android:id="@+id/schedule"
    android:icon="@drawable/schedule"
    android:title="SCHEDULE" />
 </group> 

 <group 
      android:id="@+id/group_item_4"
      android:checkableBehavior="single">
 <item
    android:id="@+id/organiser"
    android:icon="@drawable/organiser"
    android:title="ORGANISER" />
 </group> 

 <group 
      android:id="@+id/group_item_5"
      android:checkableBehavior="single">
 <item
    android:id="@+id/partners"
    android:icon="@drawable/partner"
    android:title="PARTNERS" />
 </group> 

 <group 
      android:id="@+id/group_item_6"
      android:checkableBehavior="single">
 <item
    android:id="@+id/event_info"
    android:icon="@drawable/eventinfo"
    android:title="EVENT-INFO" />
</group>

并在dimens.xml中覆盖此行以删除填充

<dimen name="design_navigation_padding_top_default" tools:override="true">0dp</dimen>
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
<dimen name="design_navigation_padding_bottom" tools:override="true">0dp</dimen>