the 'icon' attribute of action does not work?

Hi,

I want to add a tool on the MainToolBar in my plugin, the code in plugin.xml is like this:

<action id="xxx" class="com.myplugin.actions.OpenXxxAction"
text="test"
description="test description"
icon="com.myplugin.Icons.Actions.Refresh">
<add-to-group group-id="MainToolBar" anchor="last"/>
</action>

But IDEA says the icon cannot  be resolved.

If I replaced it with:

icon="AllIcons.Actions.Refresh"

It will work fine. So the problem must be icon path, but my icon and code is copied from IDEA community source. They are identical.

What's wrong with my code?

0
2 comments
Official comment

If you want to use builtin icon icon="AllIcons.Actions.Refresh" then please use it directly like this. Custom icons can be used from plugin XML but class must be located in "icons" package and name ending with "Icons", e.g. FQN would be "icons.MyPluginIcons".

I invalidated the cache, the error still exist.

Then I removed the icon attribute and overrided the update() method in OpenXxxAction,

@Override
public void update(AnActionEvent e) {
super.update(e);
e.getPresentation().setIcon(com.myplugin.Icons.Actions.Refresh);
}

After that, I get what I want. Just don't understand why the icon attribute would fail.

0

Please sign in to leave a comment.