首页 > 解决方案 > 带有自定义视图的 Flutter SplashScreen 实现

问题描述

我阅读了 Flutter 关于几个 Splash screen implementation 的文章(文章链接),我选择将它与 View 一起使用,但我不知道如何激活它。任何人都可以帮助我吗?不管怎么说,还是要谢谢你。

splash_screen_view_template

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/splash_text"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

splash_screen_view_class

public class SplashScreenView extends View {
    ...
}

splash_screen_interface

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bonfry.splash_screen.SplashScreenView;

import io.flutter.embedding.android.SplashScreen;

public class SplashScreenWithTransition implements SplashScreen {
    private SplashScreenView mySplashView;

    @Override
    @Nullable
    public View createSplashView(
            @NonNull Context context,
            @Nullable Bundle savedInstanceState
    ) {
        mySplashView = new SplashScreenView(context);
        return mySplashView;
    }

    @Override
    public void transitionToFlutter(@NonNull Runnable onTransitionComplete) {
        onTransitionComplete.run();
    }
}

标签: javaandroidflutterdart

解决方案


推荐阅读