深色模式:useColorScheme() 在 Android 上始终返回光

2024-01-03

我正在尝试让深色模式正常工作,但它在 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。

I put "userInterfaceStyle": "automatic" in my app.json但这没有什么区别。


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

应用程序.json:

{
  "expo": {
    "userInterfaceStyle": "automatic",
    "ios": {
      "userInterfaceStyle": "automatic"
    },
    "android": {
      "userInterfaceStyle": "automatic"
    }
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

深色模式:useColorScheme() 在 Android 上始终返回光 的相关文章

随机推荐