android - 为什么我的应用程序的状态栏会自动隐藏?
问题描述
我启动了一个颤振应用程序,并向该应用程序添加了一些代码,之后,当我在 android 设备上运行我的应用程序时,我的应用程序的状态栏会自动隐藏吗?
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.black,
accentColor: Colors.amber,
appBarTheme: AppBarTheme(
textTheme: ThemeData.light().textTheme.copyWith(
title: TextStyle(
color: Colors.amber,
fontFamily: 'OpenSans',
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
title: 'Currency App',
home: HomePage(),
routes: {
ExchangePage.routeName: (ctx) => ExchangePage(),
GrowsPage.routeName: (ctx) => GrowsPage(),
CurrencyPage.routeName: (ctx) => CurrencyPage(),
ReorderListItemScreen.routeName: (ctx) => ReorderListItemScreen(),
},
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
_portraitModeOnly();
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.amber),
title: const Text('Currency App'),
),
body: ImageCarousel(),
drawer: DrawerCode(),
);
}
void _portraitModeOnly() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
}
这是我的代码,我搜索了各种网站,但找不到合适的,请帮助我,谢谢
解决方案
StatusBar 不会去任何地方,你看不到它的唯一原因是你有primaryColor
黑色,这会将 AppBar 和 StatusBar 更改为相同的颜色,所以它看起来就像它消失了。如果您想独立更改 StatusBar 颜色,您可以执行以下操作:
import 'package:flutter/services.dart';
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( statusBarColor: Colors.lightBlue ));
return MaterialApp()
此外,“标题”属性已被弃用,appBarTheme: AppBarTheme()
使用“标题”之一 https://api.flutter.dev/flutter/material/TextTheme-class.html
推荐阅读
- python - Python 或 PBI 可视化 - 浓缩树形图 - 如何实现以及如何正确调用可视化?
- c++ - 来自本机 C++ 代码的节点 js 回调抛出错误
- xml - 针对我们的 XML 产品文件创建 Avro 模型问题?
- docker - 启动 gRPC-Web 抛出退出代码:127
- excel - 使用 VBA 从 FTP 服务器从具有变量名的文件夹下载
- android - 启动失败:[全新安装 ANDROID STUDIO]
- wordpress - WooCommerce REST API 无法保存使用 youtube 在描述字段中嵌入 iframe 的 HTML
- ms-access - 我可以强制行标题显示在带有动态列标题的 Access 交叉表上吗?
- elixir - 从根模板phoenix 发送输入值
- python - 我如何在 python Visual Studio Code 中使用我的 GPU