图标和NavigationView之间的左边界 [英] Left margin between icons and NavigationView

查看:208
本文介绍了图标和NavigationView之间的左边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在图标和NavigationView之间添加左侧边距,在下面的图像箭头中:

I have to add a left margin between the icons and the NavigationView, in arrow in the image bellow:

我知道根据Google的规范,此边距必须为16dp,但我需要更改它.我已经尝试过:

I know that according to google specs, this margin must have 16dp but I need to change it. I have tried:

 <dimen tools:override="true" name="design_navigation_icon_padding">64dp</dimen>
 <dimen tools:override="true" name="design_navigation_separator_vertical_padding">20dp</dimen>

但仍然无法正常工作.有什么想法吗?

But still not working. Any ideas?

推荐答案

该项目的xml布局为

The xml layout of that item is design_navigation_item.xml

<android.support.design.internal.NavigationMenuItemView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="?attr/listPreferredItemHeightSmall"
        android:paddingLeft="?attr/listPreferredItemPaddingLeft"
        android:paddingRight="?attr/listPreferredItemPaddingRight"
        android:foreground="?attr/selectableItemBackground"
        android:focusable="true"/>

如您所见,所应用的填充取自活动的主题-listPreferredItemPaddingLeftlistPreferredItemPaddingRight.因此,您必须将自定义主题应用于NavigationView,以必要的值覆盖这些属性.

As you can see, paddings that are applied are taken from the activity's theme - listPreferredItemPaddingLeft and listPreferredItemPaddingRight. Thus, you have to apply your custom theme to NavigationView overriding those attributes with necessary values.

styles.xml中:

<style name="MyNavigationViewItemStyle" parent="AppTheme">
    <item name="listPreferredItemPaddingLeft">0dp</item>
    <item name="listPreferredItemPaddingRight">0dp</item>
</style>

我们只想从活动主题中更改这两个属性,从而扩展适用于活动的主题.

We want to change only those two attributes from activity's theme, thus we are extending the theme, that is applied to the activity.

在布局xml中:

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

结果

这篇关于图标和NavigationView之间的左边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆