How to set badge in NavigationView?
<p>I use <code>NavigationDrawer</code> from desin lib</p>

<pre><code>compile 'com.android.support:design:24.0.0'
</code></pre>

<p>There is <code>XML</code></p>

<pre><code>....

&lt;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" /&gt;

....
</code></pre>

<p>There is point where i am setting menu</p>

<pre><code>app:menu="@menu/activity_third_drawer"
</code></pre>

<p>There is <code>XML</code> of menu</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu
xmlns:android="http://schemas.android.com/apk/res/android"&gt;

&lt;group android:checkableBehavior="single"&gt;
    &lt;item
        android:id="@+id/nav_inbox"
        android:icon="@drawable/ic_mail_outline_white"
        android:title="@string/inbox" /&gt;
    &lt;item
        android:id="@+id/nav_gallery"
        android:icon="@drawable/ic_close_24dp"
        android:title="@string/gallery" /&gt;
    &lt;item
        android:id="@+id/nav_slideshow"
        android:icon="@drawable/ic_close_24dp"
        android:title="@string/slideshow" /&gt;
    &lt;item
        android:id="@+id/nav_manage"
        android:icon="@drawable/ic_close_24dp"
        android:title="@string/tools" /&gt;
&lt;/group&gt;

&lt;item android:title="@string/about_app"&gt;
    &lt;menu&gt;
        &lt;item
            android:id="@+id/nav_about"
            android:icon="@drawable/ic_close_24dp"
            android:title="@string/about1" /&gt;
    &lt;/menu&gt;
&lt;/item&gt;
&lt;/menu&gt;
</code></pre>

<p>Eventually it is looks like this</p>

<p><a href="https://i.stack.imgur.com/4a5Rxl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4a5Rxl.png" alt="введите сюда описание изображения"></a></p>

<p>but I need when message is caming to inbox it should be marked in <code>NavigationDrawer</code>.</p>

<p>Like this</p>

<p><a href="https://i.stack.imgur.com/YBsiQl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YBsiQl.png" alt="введите сюда описание изображения"></a></p>

<p>There are a lot of deffirent libs that can help with this issue, I chose <a href="https://github.com/jgilfelt/android-viewbadger" rel="nofollow noreferrer">this one</a>.</p>

<p>This lib can attach badge wherever you want, but there are no one sample hoe to attach it to <code>&lt;item&gt;</code> . The closest sample is how to attach to <code>XML</code> </p>

<pre><code>&lt;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" /&gt;
</code></pre>

<p>but i still can't think out how to attach it to <code>&lt;item&gt;</code> </p>

<p>Maybe there are another solution how to make it?</p>

<p>I have tryed this way</p>

<pre><code>View menuItemView = MenuItemCompat.getActionView(navigationView.getMenu().findItem(R.id.nav_inbox));
    BadgeView badge = new BadgeView(context, menuItemView);
    badge.setText("1");
    badge.show();
</code></pre>

<p>but every time I get <code>menuItemView = null</code></p>

<p>then I have tried this way:</p>

<pre><code>@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    View menuItemView = MenuItemCompat.getActionView(menu.findItem(R.id.nav_inbox));
    BadgeView badge = new BadgeView(context, menuItemView);
    badge.setText("1");
    badge.show();

    return super.onPrepareOptionsMenu(menu);
}
</code></pre>

<p>but it is the same <code>menuItemView = null</code>:</p>

<p>Debag</p>

<p><a href="https://i.stack.imgur.com/JcDx0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JcDx0.png" alt="введите сюда описание изображения"></a></p>

<p>What I am doing wrong?</p>

<p><strong>EDIT</strong></p>

<p>My <code>NavigationView</code> </p>

<pre><code>&lt;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" /&gt;
</code></pre>

<p>My <code>menu</code></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"&gt;

&lt;group android:checkableBehavior="single"&gt;

    &lt;item
        android:id="@+id/nav_inbox"
        android:icon="@drawable/ic_inbox_checked"
        android:title="Inbox"
        app:actionLayout="@layout/badge" /&gt;

&lt;/group&gt;

&lt;item android:title="@string/about_app"&gt;
    &lt;menu&gt;
        &lt;item
            android:id="@+id/nav_about"
            android:icon="@drawable/ic_close_24dp"
            android:title="@string/about1" /&gt;
    &lt;/menu&gt;
&lt;/item&gt;
&lt;/menu&gt;
</code></pre>

<p>My <code>badge</code></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"&gt;

&lt;TextView
    android:id="@+id/textMenuItemCount"
    android:layout_width="wrap_content"
    android:text="rrrr"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:textColor="@android:color/holo_blue_light"
    android:textStyle="bold"
    android:textSize="16sp"
    android:alpha="0.6"/&gt;
&lt;/RelativeLayout&gt;
</code></pre>

<p>This is my code</p>

<pre><code>@Override
protected void onResume() {
    super.onResume();
    NavigationView navView = (NavigationView) findViewById(R.id.nav_view);
    MenuItem item = navView.getMenu().findItem(R.id.nav_inbox);
    MenuItemCompat.setActionView(item, R.layout.badge);
    RelativeLayout notifCount = (RelativeLayout) MenuItemCompat.getActionView(item);
    TextView tv = (TextView) notifCount.findViewById(R.id.textMenuItemCount);

    String count = "4";
    if (count != null) {
        tv.setText(count);
    }else{
        tv.setText("");
        item.setEnabled(false);
    }
}
</code></pre>

<p>This is screenshot debag</p>

<p><a href="https://i.stack.imgur.com/HNdSz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HNdSz.png" alt="enter image description here"></a></p>

<p>This is what I get finally </p>

<p><a href="https://i.stack.imgur.com/RGVxv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RGVxv.png" alt="enter image description here"></a></p>

<p>it is nothing, but according debug mode all is ok, without any error, but I can't see any badge.</p>

<p>What I am doing wrong?</p>