1

I'm not finding how to create a icon over text centered in the menu of a DrawerLayout. Using standard Drawer layout file with menu items. Tried adding android:gravity but that does not seem to help. Thoughts?

<?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">
        <item
            android:layout_gravity="center_horizontal"
            android:id="@+id/nav_backpack"
            android:icon="@drawable/person"
            android:title="Backpack" />
        <item
            android:id="@+id/nav_messages"
            android:icon="@drawable/messages"
            android:title="Messages" />
        <item
            android:id="@+id/nav_library"
            android:icon="@drawable/book"
            android:title="Library" />
        <item
            android:id="@+id/nav_calendar"
            android:icon="@drawable/calendar"
            android:title="Calendar" />
        <item
            android:id="@+id/nav_progress"
            android:icon="@drawable/book"
            android:title="Progress" />
        <item
            android:id="@+id/nav_account"
            android:title="Account" />
        <item
            android:id="@+id/nav_help"
            android:title="Help" />
        <item
            android:id="@+id/nav_logout"
            android:title="Logout" />
    </group>
    <group android:checkableBehavior="none">
    <item android:title="About">
        <menu>
            <item
                android:id="@+id/nav_version"
                android:icon="@drawable/ic_menu_share"
                android:title="v1.1(03)" />
        </menu>
    </item>
    </group>
</menu>

enter image description here

justdan0227
  • 1,374
  • 18
  • 48
  • 1
    you cant do that with the menu implementation as it is. I would suggest using a custom view; this might help you: https://stackoverflow.com/questions/30626324/navigationview-and-custom-layout/30644656 – Raykud Mar 08 '18 at 23:02
  • Wow this really does not exist in native Android huh? Thought I was just overlooking something. Seems so trivial. – justdan0227 Mar 09 '18 at 13:33
  • Anyone else have a solution. Can't believe I'm the only one trying this. – justdan0227 Mar 16 '18 at 12:43
  • its not native as there is a specification for the navigation drawer component https://material.io/guidelines/patterns/navigation-drawer.html# thats why you have to make it custom. – Raykud Mar 16 '18 at 18:40

0 Answers0