Kern Elliott
Kern Elliott

Reputation: 1659

Android Menu custom Icon

How can I add a custom icon to my android menu the code below is what I currently have in my xml file.

 <item android:id="@+id/item1" android:icon="@android:drawable/ic_menu_add" android:title="Blog"></item>

the icon is already within my drawable folder

Upvotes: 2

Views: 9457

Answers (3)

taha jadid
taha jadid

Reputation: 11

NavigationView navView = findViewById(R.id.navigationView);
navView.setItemIconTintList(null);

This works for me to set the original icon with the original colors.

Upvotes: 1

slybloty
slybloty

Reputation: 6506

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);

    //Set icon for the menu button
    Drawable icon = getResources().getDrawable(R.drawable.icon);
    menu.getItem(0).setIcon(icon);

    return true;
} //End onCreateOptionsMenu()

More reading: MenuItem

Upvotes: 1

Cata
Cata

Reputation: 11211

you have to replace this in the xml:

android:icon="@android:drawable/ic_menu_add"

with

android:icon="@drawable/your_menu_icon_name"

Upvotes: 6

Related Questions