简体   繁体   English

创建菜单后,如何更改菜单中的图标?

[英]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. 嗨,我是Android开发的新手,到目前为止,学习进展顺利,但是我遇到了一些麻烦,但事情可能很简单。

I've set up GCM with my app, it works fine. 我已经使用我的应用程序设置了GCM,但效果很好。 I have an icon in my android action bar that represents a notification. 我的Android操作栏中有一个代表通知的图标。 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. 提前致谢。

You can change actionbar menu item by this way. 您可以通过这种方式更改操作栏菜单项。 here menu is o nCreateOptionsMenu(Menu menu, MenuInflater inflater) . 这里的菜单是nCreateOptionsMenu(Menu menu, MenuInflater inflater)

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

Thanks 谢谢

覆盖onPrepareOptionsMenu并调用invalidateOptionsMenu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM