问题
Is it possible to change the context menu icon during runtime? There seems to be no option in the update method.
回答1:
I think what you're looking for is the setIcon
method of the BrowserAction. Within the ContextMenu you can only specify the items shown in the menu, not configure the icon itself.
http://code.google.com/chrome/extensions/browserAction.html#method-setIcon
回答2:
It's been possible for some time, include a following line to the root of your manifest.json
file:
"icons": {"16": "icon.png"}
The context menu icon size is 16px; you can also define other sizes used in different use cases.
回答3:
To expand on @Zdenek F's answer, here are step by step instructions.
- Choose/create an appropriate icon. Default sizes are 16x16, 48x48 and 128x128. More info here.
- Open your manifest.json file.
The JSON format needs to be respected.
"icons": { "16" : "icon16.png", "48" : "icon48.png", "128" : "icon128.png" }
The icon page (linked earlier) explains that Chrome attempts to use the icon size that is most appropriate. The context menu icon is closest to 16x16 - so just specify the icon you want for the context menu here. The 48x48 icon will be used on the chrome://extensions web page.
Note from Google: You should always provide a 128x128 icon; it's used during installation and by the Chrome Web Store.
So there you have it. Icon sizes and default Chrome behaviour explained. In the future, please try searching and reading through the appropriate documentation at https://developer.chrome.com
来源:https://stackoverflow.com/questions/9499620/change-context-menu-icon