StatusBar
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
用于控制应用状态栏的组件。状态栏通常位于屏幕顶部区域,显示当前时间、Wi-Fi和蜂窝网络信息、电池电量及其他状态图标。
与导航器配合使用
可以同时挂载多个StatusBar组件。属性将按照StatusBar组件挂载的顺序进行合并。
- TypeScript
- JavaScript
命令式 API
在组件使用不理想的情况下,可通过组件的静态函数调用命令式 API。但请注意,不建议对同一属性同时使用静态 API 和组件方式,因为静态 API 设置的值会在下次渲染时被组件的设置覆盖。
参考
常量
currentHeight Android
状态栏高度(包含刘海屏高度,如果存在)。
属性
animated
状态栏属性变更时是否启用过渡动画。支持backgroundColor、barStyle和hidden属性。
| Type | Required | Default |
|---|---|---|
| boolean | No | false |
backgroundColor Android
状态栏的背景色。
由于 Android 15 引入了强制边到边渲染,在 API 级别 35 中设置状态栏背景颜色已被弃用,设置将不会生效。你可以在这里阅读我们关于边到边的建议。
| Type | Required | Default |
|---|---|---|
| color | No | default system StatusBar background color, or 'black' if not defined |
barStyle
设置状态栏文本颜色。
在 Android 上,此属性仅对 API 23 及以上版本生效。
| Type | Required | Default |
|---|---|---|
| StatusBarStyle | No | 'default' |
hidden
是否隐藏状态栏。
| Type | Required | Default |
|---|---|---|
| boolean | No | false |
networkActivityIndicatorVisible iOS
是否显示网络活动指示器。
| Type | Default |
|---|---|
| boolean | false |
showHideTransition iOS
使用hidden属性显示/隐藏状态栏时的过渡效果。
| Type | Default |
|---|---|
| StatusBarAnimation | 'fade' |
translucent Android
状态栏是否半透明。设置为true时,应用内容将延伸到状态栏下方。适用于半透明状态栏颜色的场景。
由于 Android 15 引入了强制边到边渲染,在 API 级别 35 中将状态栏设置为半透明已被弃用,设置将不会生效。你可以在这里阅读我们关于边到边的建议。
| Type | Default |
|---|---|
| boolean | false |
方法
popStackEntry()
static popStackEntry(entry: StatusBarProps);
从堆栈中获取并移除最后一个 StatusBar 条目。
参数:
| Name | Type | Description |
|---|---|---|
| entry Required | any | Entry returned from pushStackEntry. |
pushStackEntry()
static pushStackEntry(props: StatusBarProps): StatusBarProps;
将 StatusBar 条目推入堆栈。返回值应在操作完成后传递给popStackEntry。
参数:
| Name | Type | Description |
|---|---|---|
| props Required | any | Object containing the StatusBar props to use in the stack entry. |
replaceStackEntry()
static replaceStackEntry(
entry: StatusBarProps,
props: StatusBarProps
): StatusBarProps;
使用新属性替换现有的 StatusBar 堆栈条目。
参数:
| Name | Type | Description |
|---|---|---|
| entry Required | any | Entry returned from pushStackEntry to replace. |
| props Required | any | Object containing the StatusBar props to use in the replacement stack entry. |
setBackgroundColor() Android
static setBackgroundColor(color: ColorValue, animated?: boolean);
设置状态栏背景色。
由于 Android 15 引入了强制边到边渲染,在 API 级别 35 中设置状态栏背景颜色已被弃用,设置将不会生效。你可以在这里阅读我们关于边到边的建议。
参数:
| Name | Type | Description |
|---|---|---|
| color Required | string | Background color. |
| animated | boolean | Animate the style change. |
setBarStyle()
static setBarStyle(style: StatusBarStyle, animated?: boolean);
设置状态栏样式。
参数:
| Name | Type | Description |
|---|---|---|
| style Required | StatusBarStyle | Status bar style to set. |
| animated | boolean | Animate the style change. |
setHidden()
static setHidden(hidden: boolean, animation?: StatusBarAnimation);
显示或隐藏状态栏。
参数:
| Name | Type | Description |
|---|---|---|
| hidden Required | boolean | Hide the status bar. |
| animation iOS | StatusBarAnimation | Animation when changing the status bar hidden property. |
🗑️ setNetworkActivityIndicatorVisible() iOS
iOS 13 及以上版本不再支持状态栏网络活动指示器。此功能将在未来版本中移除。
static setNetworkActivityIndicatorVisible(visible: boolean);
控制网络活动指示器的可见性。
参数:
| Name | Type | Description |
|---|---|---|
| visible Required | boolean | Show the indicator. |
setTranslucent() Android
static setTranslucent(translucent: boolean);
控制状态栏的半透明效果。
由于 Android 15 引入了强制边到边渲染,在 API 级别 35 中将状态栏设置为半透明已被弃用,设置将不会生效。你可以在这里阅读我们关于边到边的建议。
参数:
| Name | Type | Description |
|---|---|---|
| translucent Required | boolean | Set as translucent. |
类型定义
StatusBarAnimation
iOS 上状态栏过渡的动画类型。
| Type |
|---|
| enum |
常量:
| Value | Type | Description |
|---|---|---|
'fade' | string | Fade animation |
'slide' | string | Slide animation |
'none' | string | No animation |
StatusBarStyle
状态栏样式类型。
| Type |
|---|
| enum |
常量:
| Value | Type | Description |
|---|---|---|
'default' | string | Default status bar style (dark for iOS, light for Android) |
'light-content' | string | White texts and icons |
'dark-content' | string | Dark texts and icons (requires API>=23 on Android) |