How add Background and ImageView in Navigation Drawner

167 views Asked by At

I'm trying to change a bit the design of my sliding menu but it failed.

What I wish, is to add a section before the menu options, like playstore menu , and an image and the user logged stands .

I have this code:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/list_selector" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="25dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:contentDescription="@string/desc_list_item_icon"
    android:src="@drawable/ic_home" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_toRightOf="@id/icon"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:paddingRight="40dp"
    android:textAppearance="?android:attr/textAppearanceListItem"
    android:textColor="@color/list_item_title" />

<TextView
    android:id="@+id/counter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="8dp"
    android:background="@drawable/counter_bg"
    android:textColor="@color/counter_text_color" />

That would have to change , because I is spinning while this issue.

thanks for any input or comment

1

There are 1 answers

0
Psypher On

Just use the NavigationView provided by the android design support

In the NavigationView just provider the layout xml of the view you want above the items(like in the playstore) and the menu items can be given using a menu resource.

app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_item"

in the layout file "drawer_header" you might want to add a textview or an image which shows the logged user and give a background to the layout.

enter image description here

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/drawer_item" />

You’ll note two attributes for NavigationView: app:headerLayout controls the (optional) layout used for the header. app:menu is the menu resource inflated for the navigation items.

Reference: https://developer.android.com/reference/android/support/design/widget/NavigationView.html