首页 > 解决方案 > Flutter splashScreen for Android 如何更改背景颜色

问题描述

我想为我的颤振应用 android 版本更改 splashScreen。我已经检查了 youtube,甚至在 stackOverFlow 中的旧帖子中,我已经按照这些步骤操作,但问题是colors.xml当我启动应用程序时我没有被识别,我得到了白色的 splashScreen 几秒钟。

我附上了截图:这是colors.xml文件 在此处输入图像描述

这是launch_background.xml文件 在此处输入图像描述

您可以清楚地看到我的colors.xml文件值没有被识别。

我是新来的,我试图参考文档,但它对我来说都是混乱的,无法弄清楚头部和尾部,所以任何人都可以帮助我。我知道这对你们来说很简单。

请任何专业人士提前谢谢您。

我也尝试过无效/缓存重新启动工作室,但仍然没有结果。

这是我的main.dart

 class MyApp extends StatelessWidget {

    // This widget is the root of your application.
     @override
     Widget build(BuildContext context) {
     return MaterialApp(
     debugShowCheckedModeBanner: false,
     title: 'Flutter Demo',
      home:splash(),
      routes: <String, WidgetBuilder>{'/1': (BuildContext context) => 
      splashScreen()},
      );
     }
    }

这是我的splash.dart

// ignore: camel_case_types
class _splashState extends State<splash> {

 @override
  void initState() {
  super.initState();
  startTime();
  }

startTime() async{
  var duration = Duration(seconds: 2);
  return Timer(duration, navigationPage);
 }

void navigationPage(){
 Navigator.of(context).pushReplacementNamed('/1');
}

 @override
  Widget build(BuildContext context) {
   return Scaffold(
    backgroundColor: myColors.myBackColor,
  );
}
}

这是我的splashScreen.dart

class splashScreen extends StatefulWidget {
 @override
 _splashScreenState createState() => _splashScreenState();
 }

// ignore: camel_case_types
class _splashScreenState extends State<splashScreen> with 
SingleTickerProviderStateMixin{

 AnimationController _animationController;
 Animation _animation;
 double top= 600.0;
 AlignmentTween _alignmentTween;
 Text _text;

 @override
 void initState() {
   super.initState();
   _animationController= AnimationController(
     vsync: this,
     duration: Duration(milliseconds: 600));
   _animationController.forward();
   _animation= CurvedAnimation(
       parent: _animationController,
       curve: Curves.easeIn);
   _alignmentTween= AlignmentTween(begin: Alignment.bottomCenter, end: 
   Alignment.topCenter);
   _text= Text('MyApp Name',style: TextStyle(
     fontSize: myFontSize.titleName,
     color: myColors.mySplashTitleColor,
     fontWeight: FontWeight.bold,
     fontFamily: 'acme',
     letterSpacing: 2.0,
   ));
 }

 @override
 Widget build(BuildContext context) {

   String key;

   return Scaffold(
     backgroundColor: myColors.myBackColor,
     body: TweenAnimationBuilder(
       key: Key(key),
       child: Align(
         alignment: Alignment(0,.6),
           child: _text),
       duration: Duration(milliseconds: 500),
       tween: Tween<double>(begin: 0.0, end: 1.0),
       builder: (context, double val,Widget child){
         return Opacity(opacity: val,
         child: child,);
       },
     ),
   );
 }
}

我在 youtube 上找到的上述代码和我尝试编辑的一些博客,以便我能理解发生了什么,然后当我想到启动画面时,white color我正在尝试更改它,然后我参考了 youtube 和一些较旧的帖子StackOverFlow,按照相同的步骤,但我无法更改它。

我得到的结果:

在此处输入图像描述

标签: flutter

解决方案


尝试以下...

在 ./values/colors.xml :

<resources>
    <color name="launcher_background_color">#FFCA28</color>
</resources>

在 ./drawable/launch_background.xml :

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/launcher_background_color" />
</layer-list>

flutter clean在终端和重建

在此处输入图像描述


推荐阅读