1

I created NavigationDrawer and put needed items in it. On most devices it looks good, but on certain devices text is cutted by vertical. Items in NavigationDrawer created in menu.xml, so i used components like "menu", "group" and "item". I think if I use TextView instead, i could define margins and paddings, but in menu.xml i can not do that. Here is my menu.xml. How can I fix it?

<?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/nav_contacts"
        android:icon="@drawable/ic_contacts"
        android:title="@string/contacts" />
    <item
        android:id="@+id/nav_dialogs"
        android:icon="@drawable/ic_message"
        android:title="@string/dialogs" />
</group>

<item android:title="@string/settings">
    <menu>
        <item
            android:id="@+id/nav_settings_profile"
            android:icon="@drawable/ic_account"
            android:title="@string/profile" />
        <item
            android:id="@+id/nav_settings_notifications"
            android:icon="@drawable/ic_notifications"
            android:title="@string/notifications" />
        <item
            android:id="@+id/nav_settings_black_list"
            android:icon="@drawable/ic_black_list"
            android:title="@string/black_list" />
    </menu>
</item>

<group
    android:id="@+id/about_exit"
    android:checkableBehavior="none">
    <item
        android:id="@+id/nav_about"
        android:icon="@drawable/ic_about"
        android:title="@string/about" />
    <item
        android:id="@+id/nav_exit"
        android:icon="@drawable/ic_exit"
        android:title="@string/exit" />
</group>

Here is activity layout, where I bind my Drawer with menu.xml file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>

Screenshot :

enter image description here

1 Answers1

0

I tested using this NavigationView project and it is using the support design library version 22.2.0 and it work perfectly in the most phones I have here, samsumg s3, nexus 6, moto x, so i can't reproduce this error that you have. This error looks like a bug in some phones, i don't know what phone you are using, but I did some searchs and no one have this problem, this error may be linked with some version of android, and can be a bug of design library, I'm not sure about this.

I suggest you to:

1 - Update you design library for the most recent version and check if it works, or

2 - Implement a Navigation Drawer with listview with header and an custom adapter (Work perfectly for the most phones with android version 2.3 to 6.0), or

4 - NavigationView with custom layout (recommend) from StackOverflow answer

<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/nav_header" />

        <ListView
            android:id="@+id/lst_menu_items"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>
</android.support.design.widget.NavigationView>

or

5 - Wait for more answers or start a bounty.

Community
  • 1
  • 1
diogojme
  • 2,309
  • 1
  • 19
  • 25