I want to remove the unwanted space created in submenu.
Is there any possibility I can achieve it from menu.xml
class?
Here is my navigation_drawer_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/all"
android:checked="true"
android:icon="@drawable/ic_channels"
android:title="All Channels" />
.......
<item
android:id="@+id/other"
android:icon="@drawable/ic_other"
android:title="Others" />
</group>
<item android:title="">
<menu>
<item
android:id="@+id/setting"
android:icon="@drawable/ic_action_settings"
android:title="Settings" />
<item
android:id="@+id/about"
android:icon="@drawable/ic_about"
android:title="About" />
<item
android:id="@+id/share"
android:icon="@drawable/ic_share"
android:title="Share" />
</menu>
</item>
Thanks.
This is how I implement it. Because you are adding a title to a menu it is not recognizing it is empty.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav1"
android:checked="true"
android:title="Pos 1" />
<item
android:id="@+id/nav2"
android:title="Pos 2" />
</group>
<group
android:id="@+id/menu_two"
android:checkableBehavior="single">
<item
android:id="@+id/pos3"
android:title="Pos 3" />
<item
android:id="@+id/pos4"
android:title="Pos 4" />
</group>
</menu>
First, please read this Ian Lake's (Android Developer Advocate) answer:
NavigationView
seeks to match the material design specs for the navigation drawer which state an 8dp space between content areas. Generally there are no ways to overrideNavigationView
to specifically break the specifications.From: How I can remove the unnecessary top padding of the Navigation view?
As you see this undesired padding is sub header
of your section.
To delete it, you would need to delete this
<item android:title="">
and </item>
To do it you need ****merge** all menu elements** () into single group (no subsections).
After changes your code should look like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/all"
android:checked="true"
android:icon="@drawable/ic_channels"
android:title="All Channels" />
.......
<item
android:id="@+id/other"
android:icon="@drawable/ic_other"
android:title="Others" />
<menu>
<item
android:id="@+id/setting"
android:icon="@drawable/ic_action_settings"
android:title="Settings" />
<item
android:id="@+id/about"
android:icon="@drawable/ic_about"
android:title="About" />
<item
android:id="@+id/share"
android:icon="@drawable/ic_share"
android:title="Share" />
<menu>
</group>
Still you can do this: How to create a custom navigation drawer in android
If you have a question, please free to ask
Hope it help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With