0

I would like to give the user of my app the opportunity to change the colors of the app. He can decide between a standard colorful version (primary: blue, accent: orange) and a dark version (primary:dark grey, accent: light grey).

So in my res/values/colors.xml I would like to do it like this:

//Backup

<color name="version_default_primary">COLOR</color>
<color name="version_default_accent">COLOR</color>
<color name="version_dark_primary">COLOR</color>
<color name="version_dark_accent">COLOR</color>

When the user has chosen primary and accent color it should copy it into here:

<color name="primary">COLOR</color>
<color name="accent">COLOR</color>

How to do that? Because I dont want to save it in Sharedprefences and query every time: isDarkVersion() or isDefaultVersion() and so on...

EDIT: style.xml

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>

    </style>
XxGoliathusxX
  • 922
  • 13
  • 34
  • You should use style to set "primary" and "accent" version in your App. – shalini Sep 19 '16 at 18:39
  • pls show me how – XxGoliathusxX Sep 19 '16 at 18:46
  • @shalini I made an edit^^ – XxGoliathusxX Sep 19 '16 at 18:47
  • This might help you. Check this out [this](http://stackoverflow.com/a/14110172/5223322) – Ibrahim Ali Khan Sep 19 '16 at 20:11
  • @IbrahimAliKhan "Because I dont want to save it in Sharedprefences and query every time: isDarkVersion() or isDefaultVersion() and so on..." – XxGoliathusxX Sep 19 '16 at 20:37
  • I think you should save a reference to the style attributes in attrs.xml, use the name defined there in your themes to specify the different themes and finally use the name defined in the attrs.xml whenever you are specifying for example a color for a view. [This](https://guides.codepath.com/android/Developing-Custom-Themes) looks like a reasonably good source for this. – Pete Sep 19 '16 at 23:39

0 Answers0