1.Before onCreate insert the line to set dark mode set to no.
@Override
protected void onCreate(Bundle savedInstanceState) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
2. Note if you are putting setDefaultNightMode after onCreate then onCreate will call multiple times.
3. Another option using theme.xml
In themes.xml change:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
to
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.DarkActionBar">
4. Or third option using
- Append the following code inside your
<style>tag in thestyles.xmlfile:
<item name="android:forceDarkAllowed">false</item>
- Note: file path:
android/app/src/main/res/values/styles.xml - After step 1 you shoule have something like below:
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> ... <item name="android:forceDarkAllowed">false</item> </style> </resources>
- Maybe 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 API level 29, this means you should change the
compileSdkVersionto 29 or higher.