好的,这个已经有点老了,但是它仍然会在谷歌搜索中出现,所以在这里提供一下。
使用插件的4.x版本,可以使用SplashView来隐藏默认情况下的appBar,并且可以像普通视图一样注册,只需使用名称SPLASH_VIEW即可。
FXML应该如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.mvc.SplashView?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<SplashView fx:id="splash" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.shara.views.SplashPresenter">
<center>
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER">
<image>
<Image url="@../../../icon.png" />
</image>
</ImageView>
</center>
<bottom>
<Label BorderPane.alignment="CENTER" />
</bottom>
</SplashView>
那么它的控制器应该长这样:
import com.gluonhq.charm.down.Services;
import com.gluonhq.charm.down.plugins.LifecycleService;
import com.gluonhq.charm.glisten.afterburner.GluonPresenter;
import com.gluonhq.charm.glisten.animation.FadeInTransition;
import com.gluonhq.charm.glisten.application.MobileApplication;
import com.gluonhq.charm.glisten.control.Alert;
import com.gluonhq.charm.glisten.control.LifecycleEvent;
import com.gluonhq.charm.glisten.mvc.SplashView;
import com.shara.Shara;
import com.shara.Network;
import javafx.animation.PauseTransition;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.util.Duration;
public class SplashPresenter extends GluonPresenter<Shara> {
@FXML private SplashView splash;
public void initialize(){
splash.setShowTransitionFactory(FadeInTransition::new);
splash.setOnShown((LifecycleEvent e) -> {
PauseTransition pause = new PauseTransition(Duration.seconds(3));
pause.setOnFinished((ActionEvent f) -> {
splash.hideSplashView();
});
pause.play();
});
}
}
视图按照正常方式进行初始化,可以通过调用 hideSplashView() 方法来进行切换。
闪屏视图可以像普通视图一样进行样式设计,并且可以使用样式表。
视图可以在 AppViewManager 中注册:
public static final AppView SPLASH_VIEW = view("Splash", SplashPresenter.class, MaterialDesignIcon.PAGES)
在你的registerViewsAndDrawer方法中,替换掉
。
REGISTRY.getViews().forEach((view) -> {
view.registerView(app);
});
使用
REGISTRY.getViews().forEach((view) -> {
if(view.getId() != "SPLASH_VIEW"){
view.registerView(app);
}
});
为确保您的启动画面不会出现在抽屉中。