Wayne Davies
Wayne Davies

Reputation: 1

How do I change an icon in a menu, after the menu has already been created?

Hi I'm new to Android Development, and so far learning has been going quite well, but I've hit a snag with something that is probably dead simple.

I've set up GCM with my app, it works fine. I have an icon in my android action bar that represents a notification. What I would like to do is change this icon, upon generating a notification in the app.

This is the first time I've ever asked a question on here, so please except my apologies if the question is not detailed enough or a duplicate, I've looked at other answers, but could not seem to find an exact match for what I'm trying to do.

Thanks in advance.

Upvotes: 0

Views: 72

Answers (2)

Md Abdul Gafur
Md Abdul Gafur

Reputation: 6201

You can change actionbar menu item by this way. here menu is onCreateOptionsMenu(Menu menu, MenuInflater inflater).

menu.getItem(5 here 5 is menu number).setIcon(context.getResources().getDrawable(R.drawable.ic_action_important));

Thanks

Upvotes: 1

MineConsulting SRL
MineConsulting SRL

Reputation: 2340

Override onPrepareOptionsMenu and call invalidateOptionsMenu

Upvotes: 0

Related Questions