0

I'm using dark and light mode in my Android application. I made an attrs.xml file in the values ​​folder. and I adjusted attr values ​. And I created 2 styles in styles.xml for night and light mode. so it works on Android above 21 but doesn't work below 21. How do I fix it ????

attrs.xml

<declare-styleable name="ds">

    <attr name="backact" format="color"/>
    <attr name="toolbar_backact" format="color"/>
    <attr name="textcolor" format="color"/>



</declare-styleable>

styles.xml

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="backact">@color/backact</item>
    <item name="toolbar_backact">@color/toolbar_backact</item>
    <item name="textcolor">@color/textcolor</item>


</style>


<style name="DarkTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="backact">#0a131c</item>
    <item name="toolbar_backact">#19242e</item>
    <item name="textcolor">#FDFDFD</item>

</style>
MMG
  • 3,226
  • 5
  • 16
  • 43
Hasan Cheraghi
  • 867
  • 2
  • 11
  • 26
  • @MikeM. Check again – Hasan Cheraghi Nov 30 '19 at 10:01
  • That looks OK. Do you happen to have multiple `res/values*/` folders? If so, is the `styles.xml` you've posted in `res/values-v21/`? That would be the issue, if it is. – Mike M. Nov 30 '19 at 10:04
  • @MikeM. Nope I just use values folder – Hasan Cheraghi Nov 30 '19 at 10:09
  • Where are you using those attributes? That is, the `backact`, `toolbar_backact`, and `textcolor` attributes. – Mike M. Nov 30 '19 at 10:11
  • @MikeM. I used in widgets text color and background color – Hasan Cheraghi Nov 30 '19 at 10:15
  • Do you mean just regular widgets, in your `Activity`? Or do you mean specifically in an App Widget, like for the home screen? In either case, could you post an example of one where it's not working? – Mike M. Nov 30 '19 at 10:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/203375/discussion-between-hasan-cheraghi-and-mike-m). – Hasan Cheraghi Nov 30 '19 at 10:20
  • Never mind about my test suggestion. I just had a look at `ContextCompat`'s source, and it doesn't do any special handling for drawables on older versions. I think you're stuck with the workarounds. Sorry about that. – Mike M. Nov 30 '19 at 12:35

0 Answers0