I created an android application and when I downloaded it to my phone it appeared in dark mode.
I want my application to always be in light mode so I used the following:
super.onCreate(savedInstanceState);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
But it still showed me the app in dark mode.
How can I completely disable it?
My styles.xml file is:
<style name="CustomActivityTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- other activity and action bar styles here -->
</style>
<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/colorGraySearchText</item>
<item name="background">@color/colorGraySearch</item>
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="android:subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<!-- Text -->
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/colorGraySearchText</item>
<item name="android:textSize">16dp</item>
</style>
<style name="CustomActivityTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="CustomActivityTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="CustomActivityTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
SOLUTION:
The following steps solved my problem:
Changing in my build.gradle (app) to :
compileSdkVersion 29
targetSdkVersion 29
adding the following line to any style in my style.xml:
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
Thank you