我对这一切都很陌生.我到处搜索,找到解决这个小问题的方法.有没有办法改变状态栏颜色?此外,当我使用颜色像colors.blue我可以看到状态栏中的文本质量不好.
谢谢
appBar: AppBar(
elevation : 0.0,
leading: IconButton(
icon: Icon(Icons.menu),
tooltip: 'Navigation menu',
onPressed: null,
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
tooltip: 'Search',
onPressed: null,
),
],
),
Run Code Online (Sandbox Code Playgroud)
小智 36
@Antoine基本上你可以设置主题亮度,或者你可以使用以下方法手动覆盖appbar亮度:
appBar: new AppBar(
title: new Text(widget.title),
brightness: Brightness.light, // or use Brightness.dark
),
Run Code Online (Sandbox Code Playgroud)
请注意,这只会在白色和黑色状态文本颜色之间切换.
也许对于更自定义的颜色,如评论说你可以查看SystemChrome类.
Luc*_*Paz 11
对于IOS和Android:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Colors.white, // Color for Android
statusBarBrightness: Brightness.dark // Dark == white status bar -- for IOS.
));
Run Code Online (Sandbox Code Playgroud)
当我不使用AppBar时,可以使用更改颜色AnnotatedRegion。
import 'package:flutter/services.dart';
...
Widget build(BuildContext context) {
return Scaffold(
body: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: ...,
),
);
}
Run Code Online (Sandbox Code Playgroud)
不要使用AnnotatedRegion
应用程序不应将 AppBar 包含在自己的 [AnnotatedRegion] 中。
你应该使用:
AppBar(
backwardsCompatibility: false,
systemOverlayStyle: SystemUiOverlayStyle(statusBarColor: Colors.orange),
)
Run Code Online (Sandbox Code Playgroud)
AnnotatedRegion 帮助您更改 iOS 上的状态栏文本颜色。
import 'package:flutter/services.dart';
...
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.dark,
child: ...,
);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果您在 Scaffold 中有 AppBar,那么它就AnnotatedRegion无法工作。这是解决方案。
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.dark, // play with this
child: Scaffold(
appBar: AppBar(
brightness: Brightness.light, // play with this
),
body: Container(),
);
}
Run Code Online (Sandbox Code Playgroud)
小智 5
@Antoine这个问题让我头疼。我使用statusbarColor插件https://pub.dartlang.org/packages/flutter_statusbarcolor将状态栏颜色更改为黑色。然后,我将应用栏的亮度设置为暗,因为它是深色背景。
import 'package:flutter/material.dart';
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'package:flutter/services.dart';
void main() async{
try {
await FlutterStatusbarcolor.setStatusBarColor(Colors.black);
} catch (e) {
print(e);
}
runApp(MaterialApp(
title: 'Using Keys',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.white
),
home: InputBox(),
));
}
class InputBox extends StatefulWidget {
@override
_InputBoxState createState() => _InputBoxState();
}
class _InputBoxState extends State<InputBox> {
bool loggedIn = false;
String _email, _username, _password;
final scaffoldKey = GlobalKey<ScaffoldState>(); //a key for the state of the scaffold
final formKey = GlobalKey<FormState>(); //a key for the state of the form
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
appBar: AppBar(
//backgroundColor: Colors.white,
centerTitle: false,
brightness: Brightness.dark,
title: Text("Using Keys",
style: TextStyle(
fontSize: 24.0,
)),
elevation: 4.0,
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
也适用于安卓。
如果您需要状态栏中的黑色文本,请调用此方法:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Colors.transparent, // optional
));
Run Code Online (Sandbox Code Playgroud)
如果您需要状态栏中的白色文本,请调用此方法:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
statusBarColor: Colors.transparent, // optional
));
Run Code Online (Sandbox Code Playgroud)
因为statusBarBrightness参数仅适用于 iOS
| 归档时间: |
|
| 查看次数: |
9377 次 |
| 最近记录: |