I am trying to show a count indicator with some of the associated menu items. How do I go about doing that? I tried creating TextView children for menu items, but they don't seem to work. Here's a mockup of what I am trying to achieve (see notifier next to the Gallery option)
Asked
Active
Viewed 1,713 times
1
-
1Have a look here -- http://stackoverflow.com/questions/30560663/navigationview-menu-items-with-counter-on-the-right – Tasos Sep 24 '16 at 06:53
-
Thanks... this really helped :) – Rohan Sep 24 '16 at 19:04
2 Answers
4
If you are using NavigationView
NavigationView provides a convenient way to build a navigation drawer, including the ability to creating menu items using a menu XML file. We’ve expanded the functionality possible with the ability to set custom views for items via app:actionLayout or using MenuItemCompat.setActionView().
Example
<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:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_menu" />
drawer_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item android:id="@+id/nav_item1"
app:showAsAction="always"
android:title=""
app:actionLayout="@layout/menu_item_layout" />
</group>
</menu>
menu_item_layout.xml
you can customize as you want
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="Item text" />
</RelativeLayout>

N J
- 27,217
- 13
- 76
- 96
-
Hi there. Some general advice about the quote device, which I see you are editing into other people's material as well as your own posts. It looks like the first item is a quote (i.e. the text within comes from a manual or a speech) and the other two are not. In markup this has semantic meaning, which is "someone else said this". If _you_ are saying it, it is not a quote - which would apply to the last two items here. It is not a general highlighter. Hope that helps! – halfer Jan 09 '17 at 20:34
-
@halfer can show me the link where is it mentioned, so I can refer it in a future edit? – N J Jan 10 '17 at 02:11
-
1I am not sure what you are asking, can you be more specific? If you want to read more about what I've said above, the [HTML blockquote](https://duckduckgo.com/?q=html+blockquote) has the exact same semantic meaning. – halfer Jan 10 '17 at 10:42
-
1
-
Not the best solution but it shows the only way you can do it in NavigationView. By the way I used `app:actionViewClass="android.widget.ImageButton"` as shown in the [other answer](https://stackoverflow.com/a/9529346/1276636). – Sufian Oct 15 '19 at 10:19
1
you can create FrameLayout
in which add your Titile TextView
and above that your Count TextView
as follows
t
<FrameLayout>
<TextView></TextView> //your titile TextView
<TextView></TextView> //your count TextView which has gravity of top right and circular background drawable
</FrameLayout>

Nikhil
- 3,711
- 8
- 32
- 43