flutter - Flutter splashScreen for Android 如何更改背景颜色
问题描述
我想为我的颤振应用 android 版本更改 splashScreen。我已经检查了 youtube,甚至在 stackOverFlow 中的旧帖子中,我已经按照这些步骤操作,但问题是colors.xml
当我启动应用程序时我没有被识别,我得到了白色的 splashScreen 几秒钟。
您可以清楚地看到我的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,按照相同的步骤,但我无法更改它。
我得到的结果:
解决方案
尝试以下...
在 ./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
在终端和重建
推荐阅读
- html - 如何使输入的高度与文本的高度相同?
- pygame - 在 PyGame 中从中心点和大小创建 Rect 对象最容易理解的方法是什么?
- regex - 尝试使用 BASH 删除段落中的重复项
- firebase - Flappy 搜索栏:Firebase 修改后未更新建议
- python - subprocess.Popen 的 preexec_fn 中的信号处理不起作用
- r - 如何使用 dplyr 通过分组变量循环 ifelse 函数
- android - 如何获取适配器中的数据并将其显示在片段中?
- python - 如何使用 KIVY for Android 进行视频流
- javascript - 如何在 discord.js 中添加带有覆盖的新频道?
- python - 不知道为什么我检查数字是否为素数的代码不起作用?