【问题标题】:Dark Mode not working React Navigation React Native暗模式不起作用 React Navigation React Native
【发布时间】:2021-01-01 07:00:43
【问题描述】:

我正在努力使用 React Navigation 在 React Native 中实现暗模式。但它只更改底部栏导航器而不是其中的屏幕。你能帮我解决这个问题吗

小吃代码

https://snack.expo.io/@belgin/news-app

【问题讨论】:

    标签: react-native react-navigation react-navigation-v5 react-navigation-stack react-navigation-bottom-tab


    【解决方案1】:

    您负责在自己的组件中设置样式。您将背景设置为浅色,将导航主题设置为深色不会神奇地改变您定义的颜色。

    要更改主题以适用于您的组件,您需要使用 useTheme 挂钩在您自己的组件中设置颜色,而不是硬编码。

    import * as React from 'react';
    import { TouchableOpacity, Text } from 'react-native';
    import { useTheme } from '@react-navigation/native';
    
    function MyScreen() {
      const { colors } = useTheme();
    
      return (
        <View style={{ flex: 1, backgroundColor: colors.background }}>
          {/* screen content */}
        </View>
      );
    }
    

    https://reactnavigation.org/docs/themes/#using-the-current-theme-in-your-own-components

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-03
      • 2020-08-26
      • 1970-01-01
      • 2022-11-10
      • 2019-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多