Dark theme does not work in some devices like Samsung S9
or some with Android 13
.
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/color_primary</item>
<item name="android:windowFullscreen">false</item>
<item name="colorPrimaryDark">@color/color_primary</item>
</style>
<style name="SwitchCompatTheme" >
<item name="colorControlActivated">@color/text_color_primary</item>
</style>
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>
in manifest:
<application
android:theme="@style/AppTheme">
...
I have only differed colors and night/colors to have different design if someone sets up dark theme in their phones. Normally it works just fine, but why it does not work on every phone? How to be more sure and maybe force to dark mode if system has got dark theme option set up?
EDIT: SOlution:
I did:
In MainActiviy OnCreate
method
AppCompatDelegate.setDefaultNightMode(mode_night_follow_system)
In my AppTheme section
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
WOrks!:)