1

I see tutorial about making navigation drawer using design library here. It really does help creating navigation drawer a lot easier. But, many tutorial on internet just show a list of item with image on the left. What if I want to put a counter next to the item title? Just like next to followers and badges in the following image. Could I do that or I need to use the old way to make navigation drawer (using layout insteand of xml menu)?

enter image description here

Gustaf
  • 262
  • 1
  • 13
  • Please look at this answer to similar question: http://stackoverflow.com/questions/30560663/navigationview-menu-items-with-counter-on-the-right/33607630#33607630 – Alex Vasilkov Nov 09 '15 at 10:59

1 Answers1

1

In new NavigationDrawer they have not mention an about the counter you are lookig for. But you can avoid the older way to put counter.

Because Navigation can contain any child view so you can use it like this.

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

        <ListView
            android:entries="@array/test"
            android:id="@+id/lvData"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </android.support.design.widget.NavigationView>

So just reference your listview and give the customize layout as you want.

I know it is Older way of listview. But it will reduce the code of NavigationDrawer. I hope it helps you.

Note : Never use app:menu and child view in NavigationView at the same time. Otherwise it will overlap each other.

Moinkhan
  • 12,732
  • 5
  • 48
  • 65