代号一中工具栏中的无限旋转命令(或按钮)
Infinite Rotation Command (or button) in toolbar in Codename One
我想 'infinite' 在 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();
我想 'infinite' 在 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();