如何在NavigationView中更改子菜单项的缩进? [英] How to change the indentation of sub menu items in a NavigationView?

查看:217
本文介绍了如何在NavigationView中更改子菜单项的缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们定义带有子菜单项部分的NavigationView时.它将子项与节标题对齐:

When we define a NavigationView with a section with sub menu items. It left aligns the sub items with the section title:

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:title="Sub items">
    <menu>
        <item
            android:title="Sub item 1" />
        <item
            android:title="Sub item 2" />
    </menu>
</item>
</menu>

我尝试添加尺寸正确的透明图像进行填充:

I tried adding a transparent image with the correct size to pad:

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:title="Sub items">
    <menu>
        <item
            android:icon="@drawable/ic_transparent"
            android:title="Sub item 1" />
        <item
            android:icon="@drawable/ic_transparent"
            android:title="Sub item 2" />
    </menu>
</item>
</menu>

但默认情况下,NavigationView:

But by default the NavigationView:

  1. 在文本图标之间添加固定填充
  2. 在图标本身上增加修复大小

我找不到如何配置此填充以及图标大小的方法.

I could not find how to configure this padding nor the icon size.

问题我们如何更改子项目的缩进,以使子项目缩进更多?

Question How can we change the sub item indentation so that the sub items are more indented?

我更喜欢通过属性进行清洁,而不是插入透明图像.

I prefer to do it cleaning via an attribute rather than inserting transparent images.

推荐答案

免责声明

请参阅我对Noundla的主要问题的评论,在该问题上我解释了为什么我认为缩进不是正确的方法.

See my comment to Noundla on the main question where I explain why I think that indentation is not the right approach.

答案

话虽如此,如果您必须具有缩进,最简单的方法是在每个菜单项上都加空格.这不是理想的选择,但是当有更好的选择时,它很容易实现,理解和替换.而且它可以与内置的Android NavigationView 一起使用,而无需引入外部库:

With that said, if you must have indentation the simplest way is to pad each menu item with spaces. This is not ideal but it is simple to implement, understand and replace when a better option is available. And it works with the built-in Android NavigationView without having to introduce external libraries:

这是将起作用的代码示例:

Here is the code sample that will work:

<menu xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:title="Sub items">
    <menu>
        <item android:title="&#160;&#160;&#160;&#160;Sub item 1" />
        <item android:title="&#160;&#160;&#160;&#160;Sub item 2" />
    </menu>
   </item>
</menu>

我希望这可以节省一些时间.

I hope this saves someone out there time.

这篇关于如何在NavigationView中更改子菜单项的缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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