暗模式:useColorScheme()在Android上总是返回光

我正在尝试让暗模式工作,但它在 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但它没有什么区别。

回答

我想到了。仅仅放入"userInterfaceStyle": "automatic"app.json 根目录是不够的,我还必须分别为 iOS 和 Android 定义它:

应用程序.json:

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


以上是暗模式:useColorScheme()在Android上总是返回光的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>