skip to Main Content

Hello‚ I had a problem with the night mode in my program. Switching from the phone system to night mode did not change the black text to white. It was just black. I found a solution through stackoverflow:

<item name="android:forceDarkAllowed" tools:targetApi="q">false</item> 

I added this code to Theme night and light.

It all started to work well though.

Now, if you try to disable the dark mode for the application from this part of the phone settings, the application will not return! It only goes back when the full phone goes back.

This setting:
enter image description here

From this part I turned off my app and there is no change. It simply ignores this part. Only if I turn off the phone completely dark mode, then the app also returns to light mode.

Please help me!

2

Answers


  1. You can put this in the first line of your launcher activity’s onCreate method to disable night mode in your app.

    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    

    If you want to use Force Dark, you make sure that the app supports Android 10 and above. Also if you want to support it in dark mode, I recommend you to read this document. https://developer.android.com/guide/topics/ui/look-and-feel/darktheme

    Login or Signup to reply.
  2. Just add this line of code to your themes-night.xml file

    <item name="android:textColor">@android:color/white</item>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search