应用程序中有一个侧面菜单。如何根据当前屏幕突出显示侧面菜单中的命令?例如,如果打开主屏幕,当我打开抽屉或侧边菜单时,应该突出显示主页命令。如果用户在 home2 屏幕中,则 home2 命令应在抽屉打开时突出显示。
主屏幕
public final class Home extends Form {
public Home(Resources res) {
super(new BorderLayout());
getToolbar().setTitle("Home");
SideMenu sm = new SideMenu(HomeNew.this, res);
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
}
}
Home2 屏幕
public final class HomeNew extends Form {
public HomeNew(Resources res) {
super(new BorderLayout());
getToolbar().setTitle("Home2");
SideMenu sm = new SideMenu(HomeNew.this, res);
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
}
}
侧边菜单类
public class SideMenu {
public SideMenu(Form f, Resources res) {
FontImage homeIcon = FontImage.createMaterial(FontImage.MATERIAL_HOME, style, 3);
Command home = new Command(" Home", homeIcon) {
@Override
public void actionPerformed(ActionEvent evt) {
new Home(res).show();
}
};
f.getToolbar().addCommandToSideMenu(home);
Command home1 = new Command(" Home1", homeIcon) {
@Override
public void actionPerformed(ActionEvent evt) {
new HomeNew(res).show();
}
};
f.getToolbar().addCommandToSideMenu(home1);
Command home2 = new Command(" Home2", homeIcon) {
@Override
public void actionPerformed(ActionEvent evt) {
}
};
f.getToolbar().addCommandToSideMenu(home2);
}
}