为什么我的应用程序的状态栏会自动隐藏?
Why status bar of my app hide automatically?
我启动了一个 flutter 应用程序并向该应用程序添加了一些代码,之后,当我 运行 我的应用程序在 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()
此外,'title' 属性 已被弃用,appBarTheme: AppBarTheme()
中的那个
使用 'headline' https://api.flutter.dev/flutter/material/TextTheme-class.html
之一
我的应用程序遇到了同样的问题。
一个 Full-Screen 应用程序,没有状态栏。
您应该尝试在 AndroidManifest.xml
中找到您加载的 Theme
在我的例子中,我正在加载一些 styles.xml
像这样:
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">true</item>
</style>
我将此条目更改为 false
<item name="android:windowFullscreen">false</item>
我启动了一个 flutter 应用程序并向该应用程序添加了一些代码,之后,当我 运行 我的应用程序在 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()
此外,'title' 属性 已被弃用,appBarTheme: AppBarTheme()
中的那个
使用 'headline' https://api.flutter.dev/flutter/material/TextTheme-class.html
我的应用程序遇到了同样的问题。
一个 Full-Screen 应用程序,没有状态栏。
您应该尝试在 AndroidManifest.xml
Theme
在我的例子中,我正在加载一些 styles.xml
像这样:
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">true</item>
</style>
我将此条目更改为 false
<item name="android:windowFullscreen">false</item>