Change icon in a toolbar

22 views
Skip to first unread message

rube...@yahoo.com

unread,
Nov 10, 2016, 8:43:55 PM11/10/16
to CodenameOne Discussions
Hi,

I need to know how to change the icon of a command inside a toolbar.

My code is:
        final Toolbar tbMenu = new Toolbar();
        fmLista2.setToolBar(tbMenu);
        s = UIManager.getInstance().getComponentStyle("Toolbar");
        final FontImage iAdicion = FontImage.createMaterial(FontImage.MATERIAL_CONTROL_POINT, s);
        final FontImage iAdicionNo = FontImage.createMaterial(FontImage.MATERIAL_CONTROL_POINT_DUPLICATE, s);
        Command cmdAdicion = new Command("", iAdicion) {
            public void actionPerformed(ActionEvent evt) {
                if (!activaAdicion) {
                    txSerial.setEditable(true);
                    cbCategoria.setEnabled(true);
                    cbUM.setEnabled(true);
                    cbImpuesto.setEnabled(true);
                    btSerial.setEnabled(true);
                    atArticulo.setGrowLimit(1);
                    cmdAdicion.setIcon(iAdicionNo);
                    activaAdicion = !activaAdicion;
                } else {
                    cmdAdicion.setIcon(iAdicion);
                    txSerial.setEditable(false);
                    cbCategoria.setEnabled(false);
                    cbUM.setEnabled(false);
                    cbImpuesto.setEnabled(false);
                    btSerial.setEnabled(false);
                    atArticulo.setGrowLimit(-1);
                    activaAdicion = !activaAdicion;
                }
                fmLista2.revalidate();
            }
        };

Shai Almog

unread,
Nov 11, 2016, 12:39:38 AM11/11/16
to CodenameOne Discussions, rube...@yahoo.com
Hi,
check out the properties cross favorite star icon which is replaced dynamically.
The gist of it is that we use findCommand() to locate the button representing the command and change the icon there.
Reply all
Reply to author
Forward
0 new messages