You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在React Native/Expo中设置底部系统手势导航栏样式?

无Tab Navigator时实现Expo React Native悬浮式系统导航栏

你说的底部系统手势导航栏,iOS端叫Home Indicator,Android端是系统虚拟导航栏。不用Tab Navigator也完全能实现悬浮效果,核心是让导航栏背景透明,同时让页面内容延伸到导航栏下方,具体配置分平台操作:

前置准备

先安装Expo官方的导航栏控制库:

npx expo install expo-navigation-bar

iOS 端配置

import * as NavigationBar from 'expo-navigation-bar';
import { useEffect } from 'react';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

export default function YourScreen() {
  const insets = useSafeAreaInsets();

  useEffect(() => {
    // 设置导航栏背景透明
    NavigationBar.setBackgroundColorAsync('transparent');
    // 将导航栏设为绝对定位,悬浮在内容上方
    NavigationBar.setPositionAsync('absolute');
    // 根据页面背景设置导航栏图标颜色(可选light/dark)
    NavigationBar.setButtonStyleAsync('light');
  }, []);

  return (
    // 页面容器,确保内容延伸到导航栏下方,同时给底部内容留安全区间距
    <View style={{ flex: 1, paddingBottom: insets.bottom + 16 }}>
      {/* 你的页面内容 */}
    </View>
  );
}

Android 端配置

Android端配置更简洁,同样用expo-navigation-bar实现:

import * as NavigationBar from 'expo-navigation-bar';
import { useEffect } from 'react';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

export default function YourScreen() {
  const insets = useSafeAreaInsets();

  useEffect(() => {
    // 设置导航栏背景透明
    NavigationBar.setBackgroundColorAsync('transparent');
    // 开启半透明效果,让内容延伸到导航栏下方
    NavigationBar.setTranslucentAsync(true);
    // 根据页面背景设置图标颜色(可选light/dark)
    NavigationBar.setButtonStyleAsync('light');
  }, []);

  return (
    <View style={{ flex: 1, paddingBottom: insets.bottom + 16 }}>
      {/* 你的页面内容 */}
    </View>
  );
}

注意事项

  • 页面背景色不能和导航栏图标色过于接近,否则会影响可读性
  • paddingBottom: insets.bottom + 16是为了避免页面底部内容被悬浮导航栏遮挡,可根据需求调整间距
  • 这些配置完全独立于React Navigation的Tab Navigator,即使没有Tab栏也能生效

内容的提问来源于stack exchange,提问作者TLS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 04:28:21