如何在 React Native 中强制禁用 android 暗模式

cak*_*PHP 6 react-native android-darkmode

我使用 React-Naive 制作了一个应用程序

“反应本机”:“0.62.0”,

“反应”:“16.11.0”,

当我将 Android 设备置于黑暗模式时,我的 UI 设计受到干扰,因此我想暂时将其禁用。

请帮忙。

Dee*_*ngh 16

文件路径:android/app/src/main/res/values/styles.xml

改变

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:textColor">#000000</item>
</style>
Run Code Online (Sandbox Code Playgroud)


Bha*_*iya 15

styles.xml您可以通过在 Android 文件夹中添加此行来禁用 Android 中的强制黑暗模式

<item name="android:forceDarkAllowed">false</item>
Run Code Online (Sandbox Code Playgroud)

像这样

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:forceDarkAllowed">false</item>
        <item name="android:textColor">#000000</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

完成这些更改后,您需要再次运行应用程序,因为这些更改是本机级别的。

编辑:如果您收到有关目标 API 的错误,请像这样使用它

<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
Run Code Online (Sandbox Code Playgroud)

  • 在 &lt;style name="AppTheme"parent="Theme.AppCompat.DayNight.NoActionBar"&gt; 中将 DayNight 替换为 Light (12认同)

小智 10

对于 IOS,更改您的 info.plist

<key>UIUserInterfaceStyle</key>
    <string>Light</string>
Run Code Online (Sandbox Code Playgroud)