跳至主内容
版本:0.82

StatusBar

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

用于控制应用状态栏的组件。状态栏通常位于屏幕顶部区域,显示当前时间、Wi-Fi和蜂窝网络信息、电池电量及其他状态图标。

与导航器配合使用

可以同时挂载多个StatusBar组件。属性将按照StatusBar组件挂载的顺序进行合并。

命令式 API

在组件使用不理想的情况下,可通过组件的静态函数调用命令式 API。但请注意,不建议对同一属性同时使用静态 API 和组件方式,因为静态 API 设置的值会在下次渲染时被组件的设置覆盖。


参考

常量

currentHeight
Android

状态栏高度(包含刘海屏高度,如果存在)。


属性

animated

状态栏属性变更时是否启用过渡动画。支持backgroundColorbarStylehidden属性。

TypeRequiredDefault
booleanNofalse

backgroundColor
Android

状态栏的背景色。

警告

由于 Android 15 引入了强制边到边渲染,在 API 级别 35 中设置状态栏背景颜色已被弃用,设置将不会生效。你可以在这里阅读我们关于边到边的建议

TypeRequiredDefault
colorNodefault system StatusBar background color, or 'black' if not defined

barStyle

设置状态栏文本颜色。

在 Android 上,此属性仅对 API 23 及以上版本生效。

TypeRequiredDefault
StatusBarStyleNo'default'

hidden

是否隐藏状态栏。

TypeRequiredDefault
booleanNofalse

networkActivityIndicatorVisible
iOS

是否显示网络活动指示器。

TypeDefault
booleanfalse

showHideTransition
iOS

使用hidden属性显示/隐藏状态栏时的过渡效果。

TypeDefault
StatusBarAnimation'fade'

translucent
Android

状态栏是否半透明。设置为true时,应用内容将延伸到状态栏下方。适用于半透明状态栏颜色的场景。

警告

由于 Android 15 引入了强制边到边渲染,在 API 级别 35 中将状态栏设置为半透明已被弃用,设置将不会生效。你可以在这里阅读我们关于边到边的建议

TypeDefault
booleanfalse

方法

popStackEntry()

tsx
static popStackEntry(entry: StatusBarProps);

从堆栈中获取并移除最后一个 StatusBar 条目。

参数:

NameTypeDescription
entry
Required
anyEntry returned from pushStackEntry.

pushStackEntry()

tsx
static pushStackEntry(props: StatusBarProps): StatusBarProps;

将 StatusBar 条目推入堆栈。返回值应在操作完成后传递给popStackEntry

参数:

NameTypeDescription
props
Required
anyObject containing the StatusBar props to use in the stack entry.

replaceStackEntry()

tsx
static replaceStackEntry(
entry: StatusBarProps,
props: StatusBarProps
): StatusBarProps;

使用新属性替换现有的 StatusBar 堆栈条目。

参数:

NameTypeDescription
entry
Required
anyEntry returned from pushStackEntry to replace.
props
Required
anyObject containing the StatusBar props to use in the replacement stack entry.

setBackgroundColor()
Android

tsx
static setBackgroundColor(color: ColorValue, animated?: boolean);

设置状态栏背景色。

警告

由于 Android 15 引入了强制边到边渲染,在 API 级别 35 中设置状态栏背景颜色已被弃用,设置将不会生效。你可以在这里阅读我们关于边到边的建议

参数:

NameTypeDescription
color
Required
stringBackground color.
animatedbooleanAnimate the style change.

setBarStyle()

tsx
static setBarStyle(style: StatusBarStyle, animated?: boolean);

设置状态栏样式。

参数:

NameTypeDescription
style
Required
StatusBarStyleStatus bar style to set.
animatedbooleanAnimate the style change.

setHidden()

tsx
static setHidden(hidden: boolean, animation?: StatusBarAnimation);

显示或隐藏状态栏。

参数:

NameTypeDescription
hidden
Required
booleanHide the status bar.
animation
iOS
StatusBarAnimationAnimation when changing the status bar hidden property.

🗑️ setNetworkActivityIndicatorVisible()
iOS

弃用

iOS 13 及以上版本不再支持状态栏网络活动指示器。此功能将在未来版本中移除。

tsx
static setNetworkActivityIndicatorVisible(visible: boolean);

控制网络活动指示器的可见性。

参数:

NameTypeDescription
visible
Required
booleanShow the indicator.

setTranslucent()
Android

tsx
static setTranslucent(translucent: boolean);

控制状态栏的半透明效果。

警告

由于 Android 15 引入了强制边到边渲染,在 API 级别 35 中将状态栏设置为半透明已被弃用,设置将不会生效。你可以在这里阅读我们关于边到边的建议

参数:

NameTypeDescription
translucent
Required
booleanSet as translucent.

类型定义

StatusBarAnimation

iOS 上状态栏过渡的动画类型。

Type
enum

常量:

ValueTypeDescription
'fade'stringFade animation
'slide'stringSlide animation
'none'stringNo animation

StatusBarStyle

状态栏样式类型。

Type
enum

常量:

ValueTypeDescription
'default'stringDefault status bar style (dark for iOS, light for Android)
'light-content'stringWhite texts and icons
'dark-content'stringDark texts and icons (requires API>=23 on Android)