Change Context Menu Icon

假装没事ソ 提交于 2020-02-05 04:45:32

问题


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.

  1. Choose/create an appropriate icon. Default sizes are 16x16, 48x48 and 128x128. More info here.
  2. Open your manifest.json file.
  3. The JSON format needs to be respected.

    "icons": {
      "16" : "icon16.png",
       "48" : "icon48.png",
       "128" : "icon128.png"
    }
    
  4. 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.

  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!