'Android Dark Mode/Light Mode - android spinner dropdown popup background color
I have a conflicting issue after the Android dark mode introduction into android os, in my app i use following custom style to make the dropdown menu
in app_text_box_design.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<solid android:color="@color/colorPrimaryAppBg" />
<corners android:radius="3dp" />
<stroke android:width="1px" android:color="@color/colorPrimaryBorder" />
</shape>
</item>
<item android:width="30dp" android:gravity="right">
<bitmap android:gravity="center_vertical|right" android:src="@drawable/baseline_arrow_drop_down_white_24" />
</item>
</layer-list>
</item>
</selector>
In the Selector, i use it as below
<Spinner
android:id="@+id/spIam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/app_text_box_design"
android:padding="10dp" />
Which works fine when in Dark Mode, if define a dark background colour in the Android Dark mode, however, if the user changed to the light mode it conflicts the design, So i am wondering how can we do settings for both modes?
Solution 1:[1]
This problem is related to styles. You have to declare a particular attribute inside your activity style to override the default white from MaterialComponents.
Assuming that your drop down menu is made by menu under res folder you just have to add this attribute to the style that you are using:
<item name="android:itemBackground">@color/colorExample</item>
Please note that since you have light & dark mode you will have probably two different styles, one called styles.xml and one called styles-night.xml. Make sure to change the colour according to what mode you are.
Solution 2:[2]
You can use colors.xml for day/night theme.
colors.xml
colors.xml(night)
And also please add android:configChanges="uiMode" in your Activity of AndroidManifest.xml
<activity
android:name="MainActivity"
android:configChanges="uiMode" />
Solution 3:[3]
Try this:
- Run cmd as an administrator
- Navigate to xampp/apache/bin
- Type httpd -t
That will check the validity of your apache config file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gcantoni |
| Solution 2 | Thazin Soe |
| Solution 3 | Bob Ray |

