我想使用" afterburner"在NavigationDrawer上实现子菜单等功能。但我发现了一些问题,最佳做法是什么,使用子菜单销毁和重新创建DefaultNavigationDrawer,或者每个模块都有一个NavigationDrawer?
我在Gluon mobile app NavigationDrawer back button issue
上使用了答案代码但我的情况比较复杂。
谢谢!
答案 0 :(得分:0)
您可以从NavigationDrawer
获取DefaultNavigationDrawer
对象,之后您可以根据需要添加任意数量的项目(这些只是节点)。
如果这些项目不是ViewItem
个实例,则您必须处理用户选择它们时要执行的操作。
使用Glisten-Afterburner模板,这就是您在AppViewManager::registerViewsAndDrawer
中首先获取抽屉的方式:
public static void registerViewsAndDrawer(MobileApplication app) {
for (AppView view : REGISTRY.getViews()) {
view.registerView(app);
}
NavigationDrawer.Header header = new NavigationDrawer.Header("Gluon Mobile",
"Multi View Project",
new Avatar(21, new Image(GluonGAf1.class.getResourceAsStream("/icon.png"))));
DefaultDrawerManager drawerManager = new DefaultDrawerManager(app, header, REGISTRY.getViews()) {
{
// Get the drawer:
NavigationDrawer drawer = getDrawer();
}
};
drawerManager.installDrawer();
}
现在,您可以将NavigationDrawer.Item
添加到其items
集合中:
public static void registerViewsAndDrawer(MobileApplication app) {
for (AppView view : REGISTRY.getViews()) {
view.registerView(app);
}
NavigationDrawer.Header header = new NavigationDrawer.Header("Gluon Mobile",
"Multi View Project",
new Avatar(21, new Image(GluonGAf1.class.getResourceAsStream("/icon.png"))));
// create items
NavigationDrawer.Item subItem1 = new NavigationDrawer.Item("Sub Item 1", MaterialDesignIcon.ADD.graphic());
NavigationDrawer.Item subItem2 = new NavigationDrawer.Item("Sub Item 2", MaterialDesignIcon.ADD_BOX.graphic());
NavigationDrawer.Item subItem3 = new NavigationDrawer.Item("Sub Item 3", MaterialDesignIcon.ADD_LOCATION.graphic());
DefaultDrawerManager drawerManager = new DefaultDrawerManager(app, header, REGISTRY.getViews()) {
{
// Get the drawer:
NavigationDrawer drawer = getDrawer();
// Add items
drawer.getItems().addAll(new Separator(), subItem1, subItem2, subItem3);
// TODO: provide action based on item selected
drawer.selectedItemProperty().addListener((obs, ov, nv) -> System.out.println("Selected item " + nv));
}
};
drawerManager.installDrawer();
}
你会得到这个: