Removing the space where the title should be for menu Item

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Removing the space where the title should be for menu Item



If I set the android:title='' option in my activity_main_drawer.xml:


android:title=''


activity_main_drawer.xml



enter image description here



I get the title displayed. However I've only got one menu option in there, I dont need a title. So if I remove that line:



enter image description here



I end up with a blank space. How can I get rid of that unnecessary space?



My XML for activity_main_drawer.xml is:


activity_main_drawer.xml


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">

<item
android:id="@+id/myfolders"
android:orderInCategory="1"
android:title="My Folders"/>

<item
android:id="@+id/systemoptions"
android:orderInCategory="2"
android:title="Preferences">
<menu>
<item
android:id="@+id/system_about"
android:icon="@drawable/ic_info"
android:title="About" />
</menu>
</item>

</menu>



The code I use to add items to the menu is a function called setupMenu:


NavigationView navView = findViewById(R.id.nav_view);
Menu menu = navView.getMenu();
int x = 0;
while(x < folders.size())
menu.add(R.id.myfolders,Menu.NONE,Menu.NONE,folders.get(x++));

navView.invalidate();





have you tried android:title="@null"? Can't test it at the moment, but maybe a null is interpreted differently?
– Grisgram
Aug 6 at 9:29




2 Answers
2



Menu-Item-Menu-Item may not be the appropriate structure here. If you want the horizontal line to appear above "About" so that it appears as a separate section, use the below code structure:


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
....
....
<group android:checkableBehavior="single"
android:id="@+id/about_menu">
<item android:id="@+id/system_about"
android:title="About"
android:icon="@drawable/ic_info" />
</group>
</menu>



Menu-Group-Item is used here.





Do I change both @+id/myfolders and @+id/systemoptions to groups? Because If I only change systemoptions, I get the 'My Folders' title above 'About'. If I change them both to groups, I get the myfolders list (which is dynamically added) and not the systemoptions menu anymore.
– Chud37
Aug 6 at 9:31





See this example: stackoverflow.com/a/34891149/6388699
– Jeet Karmakar
Aug 6 at 9:57



You could use the group tag instead of nesting your items.


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">

<item
android:id="@+id/myfolders"
android:orderInCategory="1"
android:title="My Folders" />

<group
android:id="@+id/systemoptions"
android:checkableBehavior="single"
android:orderInCategory="2">
<item
android:id="@+id/system_about"
android:icon="@drawable/ic_info"
android:title="About" />
</group>

</menu>





For some reason I get the title at the bottom after I've added menu items to myfolders dynamically.
– Chud37
Aug 6 at 9:38


myfolders





can you add your code where you dynamically add add your items?
– hopeman
Aug 6 at 9:40





updated my question with the code.
– Chud37
Aug 6 at 9:45





by removing remove android:orderInCategory="1" from your item it should put the folders at the top and the dynamically added items below
– hopeman
Aug 6 at 10:15


android:orderInCategory="1"






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard