Android Disable Dark Mode programmatically using java
<p>1.Before onCreate insert the line to set dark mode set to no.</p>
<pre>
@Override
protected void onCreate(Bundle savedInstanceState) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}</pre>
<p>2. Note if you are putting setDefaultNightMode after onCreate then onCreate will call multiple times.</p>
<p>3. Another option using theme.xml</p>
<p>In themes.xml change:</p>
<pre>
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar"></pre>
<p>to</p>
<pre>
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.DarkActionBar"></pre>
<p>4. Or third option using</p>
<ol>
<li><em>Append</em> the following code inside your <code><style></code> tag in the <code>styles.xml</code> file:</li>
</ol>
<ul>
<li><code><item name="android:forceDarkAllowed">false</item></code></li>
</ul>
<ol>
<li><strong>Note</strong>: <em>file path</em>: <code>android/app/src/main/res/values/styles.xml</code></li>
<li>After step <em>1</em> you shoule have something like below:</li>
</ol>
<ul>
<li><code><resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> ... <item name="android:forceDarkAllowed">false</item> </style> </resources></code></li>
</ul>
<ol>
<li><strong>Maybe</strong> the above steps don’t help you but don’t worry, just like is said in the top of this post, this feature is released on <em>API level 29</em>, this means you should change the <code>compileSdkVersion</code> to <strong>29</strong> or higher.</li>
</ol>
<p><strong><a href="https://medium.com/@hasperong/android-disable-dark-mode-programmatically-using-java-1372530b9414">Website</a> </strong></p>