How to disable night mode in my application even if night mode is enable in android 9.0 (pie)?

前端 未结 8 773
悲&欢浪女
悲&欢浪女 2020-12-16 12:32

I created my application before the android pie has been released, in every layout I put android: background = \"white\" it works fine in every device, but when

相关标签:
8条回答
  • 2020-12-16 13:12

    You can put this, at the first line in the onCreate method of your launcher activity.

        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
    
    0 讨论(0)
  • 2020-12-16 13:12

    React Native, Ionic (cordova, capacitor)

    Actually, this answer is especially for React Native developers/apps:

    Just like all of us know, the dark mode is fully available on Android 10

    Dark theme is available in Android 10 (API level 29) and higher

    And most likely this feature ruined your app design implementation, like SVG, font, and background colors. if you decided to fully disable force dark mode you should follow this approach:

    1. Append the following code inside your <style> tag in the styles.xml file:

      <item name="android:forceDarkAllowed">false</item>
      

      Note: file path: android/app/src/main/res/values/styles.xml

    2. After step 1 you shoule have something like below:

      <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            ...
            <item name="android:forceDarkAllowed">false</item>
        </style>
      </resources>
      
    3. Maybe the above stpes don't help you but don't worry, just like is said in the top of this post, this feature is released on API level 29, this means you should change the compiledSdkVersion to 29 or higher.

    4. To Change the compiledSdkVersion you should edit the the compiledSdkVersion in the app gradle properites existed in the android/app/build.gradle file:

      android {
          compileSdkVersion 29
      
    5. Maybe you face compileSdkVersion rootProject.ext.compileSdkVersion, don't worry you should change this in the android gradle properites existed in the android/build.gradle file:

      buildscript {
          ext {
              buildToolsVersion = "SomeVersion"
              minSdkVersion = SomeVersion
              compileSdkVersion = 29 // <======= this should be 29 or higher
              targetSdkVersion = SomeVersion
      

    Hint: For being sure that you have a new build, completely delete your last build by using the rm -rf android/app/build command and uninstall the app on your Emulator/Device and then run yarn android again.

    0 讨论(0)
提交回复
热议问题