0

I was using the drawer navigation which was in android development website, but it didnt show the title or header or image in the listview, so can u show me how to add title and image in the drawer navigation which was in android development website didnt have? Like this example

Here are some of the code:<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- As the main content view, the view below consumes the entire space available using match_parent in both dimensions. --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- android:layout_gravity="start" tells DrawerLayout to treat this as a sliding drawer on the left side for left-to-right languages and on the right side for right-to-left languages. The drawer is given a fixed width in dp and extends the full height of the container. A solid background is used for contrast with the content view. -->
<ListView android:layout_weight="1" android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="fill_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="1dp" android:background="@color/Black"/> </android.support.v4.widget.DrawerLayout>

Beginner
  • 85
  • 10

3 Answers3

0

You can use this library for your implementations: From GITHUB

it will allow you to put your custom layout in your sliding menu.

Thank you,

Kishan Dhamat
  • 3,746
  • 2
  • 26
  • 36
0

here is the solution :

in your project, create a new xml file.and paste below code in the xml viewer.after that in the graphical view you can see your customised list view.

<RelativeLayout 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_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:contentDescription="@string/desc_list_item_icon"
    android:src="@drawable/ic_home"
    android:layout_centerVertical="true" />

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

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

and go to your list view adapter [because in your navigation drawer you are using a list view to show the menu items.] in gat view method change the layout for your newly created layout [the list item that we created now]

this is my get view method.it might be different from your getview method.but i guess this will help you.

public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater)
                context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.drawer_list_item_old, null);
    }

    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
    TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
    TextView txtCount = (TextView) convertView.findViewById(R.id.counter);

    imgIcon.setImageResource(navDrawerItems.get(position).getIcon());        
    txtTitle.setText(navDrawerItems.get(position).getTitle());

    // displaying count
    // check whether it set visible or not
    if(navDrawerItems.get(position).getCounterVisibility()){
        txtCount.setText(navDrawerItems.get(position).getCount());
    }else{
        // hide the counter view
        txtCount.setVisibility(View.GONE);
    }

    return convertView;
}
Darshana
  • 314
  • 2
  • 4
  • 22
  • it is an array which is contains the names should be shown in the navigation list. such as Home,Settings etc – Darshana Mar 26 '14 at 09:14
0

You have to create custom Adapter class with your custom layout and set that adapter to list view. Check the question and answer here

Community
  • 1
  • 1
Prakash M
  • 651
  • 3
  • 13