如何创建底部导航

时间:2016-11-23 03:54:57

标签: java netbeans gluon-mobile

我是移动开发的新手,我开始使用Gluon mobile for Netbeans,我试图将底部导航栏添加到默认的Gluon Mobile App。他们在JavaDoc http://docs.gluonhq.com/charm/javadoc/4.1.0/com/gluonhq/charm/glisten/control/BottomNavigation.html中描述了这个类,但我似乎无法使其工作。 有人能够发布一个片段,说明如何以及在何处执行此操作?

1 个答案:

答案 0 :(得分:0)

这是一个简单的例子:

public class GluonApplication extends MobileApplication {

@Override
public void init() {

    addViewFactory(HOME_VIEW, () ->
    {

        StackPane root = new StackPane();
        root.getChildren().add(new Label("test"));

        View view = new View(root) {

            @Override
            protected void updateAppBar(AppBar appBar) {
                appBar.setTitleText("Home");
            }

        };
        view.setBottom(createBottomNavigation());
        return view;
    });

}

private BottomNavigation createBottomNavigation() {
    BottomNavigation bottomNavigation = new BottomNavigation();

    ToggleButton btn1 = bottomNavigation.createButton("View1", MaterialDesignIcon.DASHBOARD.graphic(), e -> showView("view1"));
    ToggleButton btn2 = bottomNavigation.createButton("View2", MaterialDesignIcon.AC_UNIT.graphic(), e -> showView("view2"));
    ToggleButton btn3 = bottomNavigation.createButton("View3", MaterialDesignIcon.MAP.graphic(), e -> showView("view3"));

    bottomNavigation.getActionItems().addAll(btn1, btn2, btn3);

    return bottomNavigation;
}

private void showView(String viewName) {
    MobileApplication.getInstance().switchView(viewName);
}

}