Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Drawer Item icon Right Side [duplicate]

I am begineer. I want to know , How to add a Item inside Navigation Drawer which icon will be add right side of Item Title.

Exactly I want to do like this picture.

see this

But how? I want to add item exactly like this Youtube Item.

This is Navigation Drawer Menu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:title="Social Links">
        <menu>
            <item
                android:id="@+id/nav_facebook"
                android:icon="@drawable/ic_menu_facebook"
                android:title="Facebook"
                />
            <item
                android:id="@+id/nav_youtube"
                android:icon="@drawable/ic_menu_youtube"
                android:title="Youtube"
                />
            <item
                android:id="@+id/nav_twitter"
                android:icon="@drawable/ic_menu_twitter"
                android:title="Twitter"
                />

        </menu>
    </item>

</menu>

I also attached this code in Manifest:

android:supportsRtl="true"
like image 405
SabbirTT Avatar asked Dec 04 '22 21:12

SabbirTT


1 Answers

Under res layout folder, create a layout named menu_image.xml. This layout is used to render image next to YouTube label.

menu_image.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="6dp"
        android:layout_height="6dp"
        android:background="@drawable/addyourimage"></LinearLayout>

</LinearLayout>

Activity:

 navigationView.getMenu().getItem(5).setActionView(R.layout.menu_image);

More Referencer

like image 76
Gowthaman M Avatar answered Dec 24 '22 13:12

Gowthaman M