I what to change background as night mode changes.
I have /values and /values-night folder, that contain "colors.xml" with different values. `
<color name="grey1">#ebebeb</color>
<color name="grey2">#c7c7c7</color>
<color name="grey3">#999999</color>
<color name="hover1">#8bb065</color>
<color name="red1">#ba0000</color>
<color name="red2">#ff0000</color>
<color name="green1">#336600</color>
<color name="text1">#000000</color>
and other is
<color name="grey1">#999999</color>
<color name="grey2">#333333</color>
<color name="grey3">#000000</color>
<color name="hover1">#8bb065</color>
<color name="red1">#ba0000</color>
<color name="red2">#ff0000</color>
<color name="green1">#336600</color>
<color name="text1">#ffffff</color>
these colors are used in layer list for background "activity_main_bg2.xml":
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/grey1" />
</shape>
</item>
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp">
<shape android:shape="rectangle" >
<solid android:color="@color/grey2" />
</shape>
</item>
</layer-list>
My activity contains fragment:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world_dark"
android:background="@drawable/activity_main_bg2" />
When I change time from day-night or back colors in background does not change. But if I use
android:background="@color/grey1"
everythings works ok.
How to solve this? Is this android bug?
And one of the major announcements of 2019 was definitely the introduction of Dark Theme on Android during the I/O, and right after that on iOS during the WWDC (called the Dark Mode in Cupertino).
Turn Dark theme on or off in your phone's settings On your phone, open the Settings app. Tap Display. Turn Dark theme on or off.
Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import. Figure 3: Select Import Drawables from the dropdown menu.
Please try this:
Add to both of them style for your TextView like:
<style name="textViewStyle">
<item name="android:background">@drawable/activity_main_bg2</item>
</style>
Update your layout to:
<TextView
style="@style/textViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world_dark" />
This solution should get property color dependent of day/night mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With