Reputation: 37367
I am trying to set background to my Android app.
But setting it with android:background
property does not work:
<GridLayout ...
android:background="#ffffff00">
I even set the background on parent element:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff00">
But it still shows me just dark background.
I have dark mode truned on on my mobile (Xiaomi if that matters). When I switch this mode off, backgrounds work as expected.
So I would like to know how to override dark mode in a app?
It looks like that this dark mode overrides already this property and it is not possible.
Upvotes: 0
Views: 377
Reputation: 37367
Based on answer of @Colex-MSFT I got it resolved:
he was right with suggestion that I should put
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
in res/values/styles.xml)
. Then I inspected it once again and out that project is autmatically created with following section in the file:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
Customize your theme here.
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
(those colors are just defined in colors.xml
file) so, I just commented out this (maybe will delete) and just left suggested line and it works - dark mode is no more forced in my application :)
Upvotes: 0
Reputation: 14475
How did you make your app support dark mode ?
I followed the docs ,just set the app's theme (usually found in res/values/styles.xml
) to inherit from a DayNight
theme:
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
Same code works as expected on my side .(The yellow part is GridLayout)
Suggestion :
Upvotes: 1