android - 如果添加 Splashscreen,Flutter 中其他屏幕的状态栏不会显示
问题描述
在添加 SplashScreen 后Flutter
,状态栏未显示在主活动中。
如果我打开 style.xml
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">true</item>
</style>
因为这个问题出现=>
<item name="android:windowFullscreen">true</item>
如何仅为 SplashScreen 设置全屏并为所有其他屏幕显示状态栏?
颤振代码
import 'package:flutter/material.dart';
import 'package:sixbrix/screens/login.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
return MaterialApp(
debugShowCheckedModeBanner: true,
title: 'Flutter',
theme: ThemeData(
primarySwatch: createMaterialColor(Color(0xFFD96332)),
),
home: MyHomePage(title: 'Flutter App'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
return Scaffold(
body: Text("Hello"),
);
}
}
MaterialColor createMaterialColor(Color color) {
List strengths = <double>[.05];
Map swatch = <int, Color>{};
final int r = color.red, g = color.green, b = color.blue;
for (int i = 1; i < 10; i++) {
strengths.add(0.1 * i);
}
strengths.forEach((strength) {
final double ds = 0.5 - strength;
swatch[(strength * 1000).round()] = Color.fromRGBO(
r + ((ds < 0 ? r : (255 - r)) * ds).round(),
g + ((ds < 0 ? g : (255 - g)) * ds).round(),
b + ((ds < 0 ? b : (255 - b)) * ds).round(),
1,
);
});
return MaterialColor(color.value, swatch);
}
解决方案
试试我下面的代码
import 'package:flutter/services.dart';
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values); //add this line
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset(
'images/splash_logo.png',
width: 50.0,
height: 100.0,
fit: BoxFit.contain,
),
SizedBox(
height: 10.0,
),
Text(
"Any",
),
),
],
),
),
);
}
这个了解更多信息:
// to hide only bottom bar:
SystemChrome.setEnabledSystemUIOverlays ([SystemUiOverlay.top]);
// to hide only status bar:
SystemChrome.setEnabledSystemUIOverlays ([SystemUiOverlay.bottom]);
// to hide both:
SystemChrome.setEnabledSystemUIOverlays ([]);
推荐阅读
- c - 为什么这个程序在第一次 scanf 之后进入无限循环?
- python - 在使用多类分类器进行预测之前过滤掉类
- java - 当我从前一个微调器中选择值时,如何获取微调器中某个子节点的值?
- xaml - 我可以在 XAML X:Static 中使用 bool 类型吗?
- javascript - 我怎样才能让这个下拉列表显示所有五十个州而不是“选项#”
- docker - 如何从 docker 容器访问 docker cmd?
- c++ - 您如何将 std::unique_ptr 初始化为引用
- ubuntu - WSL:Cabal 无法解决依赖关系。容器,二进制
- python - API 调用在工作数百次后失败……有什么想法吗?
- spring-boot - 如何修复:java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapable?