android - How to change the indentation of sub menu items in a NavigationView? -


when define navigationview section sub menu items. left aligns sub items 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> 

enter image description here

i tried adding transparent image correct size 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> 

enter image description here

but default navigationview:

  1. adds fixed padding between icon text
  2. enforces fixes size on icon itself

i not find how configure padding nor icon size.

question how can change sub item indentation sub items more indented?

i prefer cleaning via attribute rather inserting transparent images.

disclaimer

see comment noundla on main question explain why think indentation not right approach.

answer

with said, if must have indentation simplest way pad each menu item spaces. not ideal simple implement, understand , replace when better option available. , works built-in android navigationview without having introduce external libraries:

here code sample 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 saves out there time.


Comments