Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customise Navigation Drawer item height

Hello guys I'm trying to change the height of my Navigation Drawer items and I don't know how, I've looked everywhere and did my best but nothing seems to work..

Result

This is my Navigation Drawer item which is customised to have a text under that image but also I want that image to be a little bigger.

The result I am looking up to is this:

Menu Items

With around 75dp of height for each item and also I want the menu to be shorter on the width to give that look in that image.

I am using a custom layout for my items of course, which I named: menu_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_margin="10dp">

    <ImageView
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:src="@drawable/menu_icon"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Menu Title"
        android:textSize="16sp"
        android:textColor="@color/white" />

</LinearLayout>

my activity_main.xml

<?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:background="@color/colorPrimaryDark"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

and finally the menu; activity_main_drawer.xml

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

        <item
            android:id="@+id/nav_profile"
            app:actionLayout="@layout/menu_item"/>
</menu>

Any ideas how to achieve what I want? Thanks in advance

EDIT: When I enlarge the image in my custom item as follows:

this is in menu_item.xml

<ImageView
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:src="@drawable/menu_icon"/>

..I get this result:

result2

As you see my image is bigger than the item..

like image 259
siriuseteor77 Avatar asked Jun 20 '17 05:06

siriuseteor77


Video Answer


2 Answers

add this to your styles.xml

<style name="NavigationTheme" parent="AppTheme">
        <item name="listPreferredItemHeightSmall">60dp</item><!-- menu item height- vary as u need -->
    </style>

and your navigation view in drawer layout shd include that theme lik this

<android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:theme="@style/NavigationTheme"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />
like image 65
Moulesh Avatar answered Oct 17 '22 02:10

Moulesh


make custom layout

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

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

</android.support.design.widget.NavigationView>
like image 26
Aashutosh Kumar Avatar answered Oct 17 '22 02:10

Aashutosh Kumar