Force app widget's light theme on OnePlus phone with Android 12

639 Views Asked by At

I have a problem with forcing a light theme of home screen app widget on OnePlus 9 phone with Android 12 (using the OnePlus' launcher). My widget's theme inherits from Theme.MaterialComponents.Light and is light on Android 11 and below, even when the phone is in the dark mode.

Problem is on Android 12, where the widget's background is always very dark, when the phone is in the dark mode. When I set pure white background, it ends-up almost black. Pure red is dark red, pure green is dark green, etc. Looks like something in the system is tinting the background colors. The same is happening with Theme.Material3.Light and @android:style/Theme.DeviceDefault themes.

Everything is good on pure Android in an emulator, so this looks like a OnePlus issue. Any ideas what can be wrong and how to fix this?

2

There are 2 best solutions below

0
On BEST ANSWER

Goto to your themes file and place the following line in the style you are using for your app.

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

You can create a Application Class which extends Application() and place the following code in OnCreate() like this

    class YourApplicationClass : Application(){
    override fun onCreate() {
        super.onCreate()
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
    }
}

Then in your manifest file add this application class like this

<application
        android:name=".base.YourApplicationClass" 
        ...
       />