java-代号一的工具栏中的无限旋转命令(或按钮)

我想在Codename One Toolbar中“无限”旋转我的命令(刷新命令)(直到加载完成,然后我要停止旋转,但是图像仍然必须可见).我可以更改图标使其开始旋转吗?我怎样才能达到这个结果?

旋转时旋转的图标不应是可单击的,但实现起来应该不会那么困难.

解决方法:

您可以使用工具栏API和一些技巧.我创建了以下方法来做到这一点:

private void showTitleProgress(Toolbar t) {
    int pos = t.getComponentCount() - 1; //If you have a command on the left like back command
    //int pos = t.getComponentCount(); //If you don't have a command on the left like back command
    InfiniteProgress ip = new InfiniteProgress();
    ip.setAnimation(YourProgressImage);
    ip.setUIID("icon");
    Container contIp = FlowLayout.encloseCenterMiddle(ip);

    Component.setSameWidth(t.getComponentAt(pos), contIp);
    Component.setSameHeight(t.getComponentAt(pos), contIp);
    t.replaceAndWait(t.getComponentAt(pos), contIp, null);
    t.revalidate();
}

private void hideTitleProgress(Toolbar t, Command cmd) {
    int pos = t.getComponentCount() - 1; //If you have a command on the left like back command
    //int pos = t.getComponentCount(); //If you don't have a command on the left like back command
    Button cmdButton = new Button(cmd.getIcon());
    cmdButton.setUIID("TitleCommand");
    cmdButton.setCommand(cmd);
    t.replaceAndWait(t.getComponentAt(pos), cmdButton, null);
    t.getComponentForm().revalidate();
}

将其与工具栏API和您的表单一起使用,如下所示:

private Command myCommand = new Command("");
Form f = new Form("Test form");
Toolbar t = new Toolbar();
f.setToolbar(t);

Command back = new Command("Back") {

    @Override
    public void actionPerformed(ActionEvent evt) {
       //Do stuff
    }
};
back.putClientProperty("uiid", "BackCommand");
f.setBackCommand(back);
t.addCommandToLeftBar(back);

myCommand = new Command(YourProgressImage) {

    @Override
    public void actionPerformed(ActionEvent evt) {
        //To show the progress when some actions are being performed 
        showTitleProgress(t);
        //When you're done, discard the progress and restore your command
        hideTitleProgress(t, myCommand);
    }
}
myCommand.putClientProperty("TitleCommand", true);
t.addCommandToRightBar(myCommand);
f.show();
上一篇:Android Studio中没有全角工具栏?


下一篇:layui中的table中toolbar自定义过程