And I use in the application NavigationDrawer
from the library of support
compile 'com.android.support:design:24.0.0'
Here is the XML
.... <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_main_second" app:menu="@menu/activity_third_drawer" /> ....
The menu that I install here
app:menu="@menu/activity_third_drawer"
Here is the XML
code
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:checkableBehavior="single"> <item android:id="@+id/nav_inbox" android:icon="@drawable/ic_mail_outline_white" android:title="@string/inbox" /> <item android:id="@+id/nav_gallery" android:icon="@drawable/ic_close_24dp" android:title="@string/gallery" /> <item android:id="@+id/nav_slideshow" android:icon="@drawable/ic_close_24dp" android:title="@string/slideshow" /> <item android:id="@+id/nav_manage" android:icon="@drawable/ic_close_24dp" android:title="@string/tools" /> </group> <item android:title="@string/about_app"> <menu> <item android:id="@+id/nav_about" android:icon="@drawable/ic_close_24dp" android:title="@string/about1" /> </menu> </item> </menu>
And in the end it looks like this
I want when I get messages in the inbox, so that it is noted in NavigationDrawer
Like this
Different libraries can do this. I chose this one.
She can cling badges anywhere, but there is not a single example of how to attach to <item>
... There is an example of how to hook into XML
<com.readystatesoftware.viewbadger.BadgeView android:id="@+id/badge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="OK" />
But I still do not understand how to attach it to <item>
.
Can there be other solutions how to do this?
Debag
onPrepareOptionsMenu
@Override public boolean onPrepareOptionsMenu(Menu menu) { View menuItemView = MenuItemCompat.getActionView(navigationView.getMenu().findItem(R.id.nav_inbox)); BadgeView badge = new BadgeView(context, menuItemView); badge.setText("1"); badge.show(); return super.onPrepareOptionsMenu(menu); }