【问题标题】:Dark Mode: useColorScheme() always returns light on Android暗模式:useColorScheme() 在 Android 上总是返回光
【发布时间】:2021-09-15 11:34:26
【问题描述】:

我正在尝试让深色模式工作,但它在 Android 上不起作用。它总是返回“光”。在 iOS 上运行良好。

import React from 'react';
import { useColorScheme } from "react-native";

export default function App() {
  const theme = useColorScheme();
  alert("your color scheme is: " + theme); // always returns "light" on Android
  return null;
}

我正在使用 Expo SDK 42。

我将"userInterfaceStyle": "automatic" 放在我的app.json 中,但没有任何区别。

【问题讨论】:

标签: android react-native expo darkmode


【解决方案1】:

我想通了。仅将"userInterfaceStyle": "automatic" 放在 app.json 根目录中是不够的,我还必须为 iOS 和 Android 单独定义它:

app.json:

{
  "expo": {
    "userInterfaceStyle": "automatic",
    "ios": {
      "userInterfaceStyle": "automatic"
    },
    "android": {
      "userInterfaceStyle": "automatic"
    }
  }
}

【讨论】:

  • 哦,天哪,这太荒唐了。它绝对应该添加到文档中,或者只是修复为回退到顶级值。谢谢!
【解决方案2】:

为我工作

{
  expo {
    "userInterfaceStyle": "automatic",
    "ios": {
     "userInterfaceStyle": "automatic"
    },
    "android": {
     "userInterfaceStyle": "automatic"
    }

  }
}

【讨论】:

    猜你喜欢
    • 2020-03-23
    • 2020-07-12
    • 2023-02-16
    • 1970-01-01
    • 2011-06-18
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多