如何创建底部导航 [英] How to create Bottom Navigation
本文介绍了如何创建底部导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是移动开发的新手,我开始将 Gluon mobile 用于 Netbeans,我正在尝试将底部导航栏添加到默认的 Gluon 移动应用程序.他们在 JavaDoc http://docs.gluonhq.com/charm/javadoc/4.1.0/com/gluonhq/charm/glisten/control/BottomNavigation.html 但我似乎无法让它工作.有人可以发布关于如何以及在何处执行此操作的片段吗?
I am new to mobile development, I started using Gluon mobile for Netbeans and I'm trying to add a Bottom navigation bar to the default Gluon Mobile App. They describe the class in the JavaDoc http://docs.gluonhq.com/charm/javadoc/4.1.0/com/gluonhq/charm/glisten/control/BottomNavigation.html but I can't seem to make it work. Would someone be able to post a snippet on how and where to do this?
推荐答案
这是一个简单的例子:
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);
}
}
这篇关于如何创建底部导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文