"How to Create Bottom Navigation" Gluon (createButton) 有问题
Trouble with "How to Create Bottom Navigation" Gluon (createButton)
我正在尝试向我的 Gluon Mobile 应用程序添加底部导航,所以我环顾四周发现了这个:。我试图将它实现到我的代码中,但没有用,所以我将它转移到一个空的单视图项目中。在那里,我能够在 一些故障排除和导入包后 确定特定错误。如下(带两个星号的代码是产生错误的代码,以下是错误):
BottomNavigationButton btn1 = bottomNavigation.**createButton**("View1", MaterialDesignIcon.DASHBOARD.graphic(), e -> showView("view1"));
BottomNavigationButton btn2 = bottomNavigation.**createButton**("View2", MaterialDesignIcon.AC_UNIT.graphic(), e -> showView("view2"));
BottomNavigationButton btn3 = bottomNavigation.**createButton**("View3", MaterialDesignIcon.MAP.graphic(), e -> showView("view3"));
每行错误:
找不到标志
符号:方法 createButton(String,Node,(e)->showV[...]ew2"))
位置:BottomNavigation
类型的变量 bottomNavigation
完整代码如下:
package com.myfirstapplication;
import com.gluonhq.charm.glisten.application.MobileApplication;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.BottomNavigation;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import com.gluonhq.charm.glisten.visual.Swatch;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class MyFirstApplication 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();
BottomNavigationButton btn1 = bottomNavigation.createButton("View1", MaterialDesignIcon.DASHBOARD.graphic(), e -> showView("view1"));
BottomNavigationButton btn2 = bottomNavigation.createButton("View2", MaterialDesignIcon.AC_UNIT.graphic(), e -> showView("view2"));
BottomNavigationButton 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);
}
}
您应该始终首先查看 JavaDoc。查看 CreateButton method 的文档。
此方法已弃用并随后被删除。折旧消息准确描述了您必须使用的东西。
重申一下,在查看文档之前不要开始在互联网上搜索答案。好的起点是 https://docs.gluonhq.com/
Glisten 框架(移动 UI)的最新 JavaDoc 在 https://docs.gluonhq.com/charm/javadoc/6.0.6/com.gluonhq.charm.glisten/module-summary.html
我正在尝试向我的 Gluon Mobile 应用程序添加底部导航,所以我环顾四周发现了这个:
BottomNavigationButton btn1 = bottomNavigation.**createButton**("View1", MaterialDesignIcon.DASHBOARD.graphic(), e -> showView("view1"));
BottomNavigationButton btn2 = bottomNavigation.**createButton**("View2", MaterialDesignIcon.AC_UNIT.graphic(), e -> showView("view2"));
BottomNavigationButton btn3 = bottomNavigation.**createButton**("View3", MaterialDesignIcon.MAP.graphic(), e -> showView("view3"));
每行错误: 找不到标志 符号:方法 createButton(String,Node,(e)->showV[...]ew2")) 位置:BottomNavigation
类型的变量 bottomNavigation完整代码如下:
package com.myfirstapplication;
import com.gluonhq.charm.glisten.application.MobileApplication;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.BottomNavigation;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import com.gluonhq.charm.glisten.visual.Swatch;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class MyFirstApplication 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();
BottomNavigationButton btn1 = bottomNavigation.createButton("View1", MaterialDesignIcon.DASHBOARD.graphic(), e -> showView("view1"));
BottomNavigationButton btn2 = bottomNavigation.createButton("View2", MaterialDesignIcon.AC_UNIT.graphic(), e -> showView("view2"));
BottomNavigationButton 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);
}
}
您应该始终首先查看 JavaDoc。查看 CreateButton method 的文档。 此方法已弃用并随后被删除。折旧消息准确描述了您必须使用的东西。
重申一下,在查看文档之前不要开始在互联网上搜索答案。好的起点是 https://docs.gluonhq.com/ Glisten 框架(移动 UI)的最新 JavaDoc 在 https://docs.gluonhq.com/charm/javadoc/6.0.6/com.gluonhq.charm.glisten/module-summary.html