This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo NavigationBar
一个用于访问 Android 原生导航栏上各种交互的库
expo-navigation-bar 提供了一个组件和命令式 API,用于控制 Android 设备上的应用导航栏,允许你更改其按钮的颜色或将其隐藏
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
在应用配置中配置
如果你的项目中使用配置插件(Continuous Native Generation(CNG)),则可以使用其内置的配置插件配置 expo-navigation-bar。该插件允许你配置各种无法在运行时设置、必须构建新的应用二进制文件才能生效的属性。如果你的应用不使用 CNG,则需要手动配置此库
Example app.json with config plugin
Configurable properties
Are you using this library in an existing React Native app?
如果你不使用 Continuous Native Generation(CNG),或者你手动使用原生 android 项目,则需要将以下配置添加到你的原生项目中:
-
要在 Android 上隐藏导航栏,请将
expoNavigationBarHidden添加到 android/app/src/main/res/values/styles.xml:<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar"> <!-- ... --> <item name="expoNavigationBarHidden">true</item> </style>
用法
API
import { NavigationBar } from 'expo-navigation-bar';
Component
Type: React.Element<NavigationBarProps>
A component that allows you to configure your navigation bar declaratively.
You will likely have multiple NavigationBar components mounted in the same app at the same time.
For example, if you have multiple screens in your app, you may end up using one per screen.
The props of each NavigationBar component will be merged in the order that they were mounted.
NavigationBarStyle • Default: 'auto'Sets the color of the navigation bar buttons. Default value is "auto"
which picks the appropriate value according to the active color scheme,
eg: if your app is dark mode, the style will be "light".
This will have an effect when the following conditions are met:
- The device navigation bar is using buttons.
- The
enforceContrastoption of theexpo-navigation-barplugin is set tofalse.
Due to a bug in the Android 15 emulator this function may have no effect. Try a physical device or an emulator with a different version of Android.
Component methods
Set the navigation bar's visibility.
voidExample
NavigationBar.setHidden(true);
Sets the style of the navigation bar.
This will have an effect when the following conditions are met:
- The device navigation bar is using buttons.
- The
enforceContrastoption of theexpo-navigation-barplugin is set tofalse.
Due to a bug in the Android 15 emulator this function may have no effect. Try a physical device or an emulator with a different version of Android.
voidExample
NavigationBar.setStyle("dark");
Hooks
Deprecated: This will be removed in a future release.
React hook that statefully updates with the visibility of the system navigation bar.
NavigationBarVisibility | nullVisibility of the navigation bar, null during async initialization.
Methods
Deprecated: This will be removed in a future release.
Get the navigation bar's visibility.
Promise<NavigationBarVisibility>Navigation bar's current visibility status. Returns hidden on unsupported platforms (iOS, web).
Deprecated: Use
NavigationBar.setStyleinstead. This will be removed in a future release.
voidDeprecated: Use
NavigationBar.setHiddeninstead. This will be removed in a future release.
Set the navigation bar's visibility.
Promise<void>Event subscriptions
Deprecated: This will be removed in a future release.
Observe changes to the system navigation bar. Due to platform constraints, this callback will also be triggered when the status bar visibility changes.
EventSubscriptionTypes
Literal type: string
Navigation bar style.
autowill automatically adjust based on the current theme.lighta light navigation bar with dark content.darka dark navigation bar with light content.invertedthe bar colors are inverted in relation to the current theme.
Acceptable values are: 'auto' | 'inverted' | 'light' | 'dark'
Deprecated: This will be removed in a future release.
Literal type: string
Visibility of the navigation bar.
Acceptable values are: 'visible' | 'hidden'