6

Theme colors can be changed if multiple themes added in app and can be switched at run time easily. Other way is to change the color of actiobar, textview etc one by one of all the object. This way is very long and take lots of code. Simple way i found is to change colors declare in colors.xml file but i could not find a way programmatically or third party library to do that. Is there a way to do this.

My Colors XML File:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#ea1e63</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>

I just want to change colorPrimary color at runtime, this will change color on all app activities. I found https://github.com/negusoft/GreenMatter, to change colors at runtime but its old and dont work with android studio.

DIGITAL JEDI
  • 1,672
  • 3
  • 24
  • 52

1 Answers1

0

when you apply theme and want to change color than

EX :

activity.setTheme(R.style.green);


<style name="green">
        <item name="main_background">@drawable/background_green</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="button_light">@color/button_light</item>
</style>

theme color can not be change at runtime of a particular theme.

Make custom style and change these styles when you want to change color in your application.

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
  • 4
    please read the question carefully, i dont want to switch theme at run time. I want to change color value save in color.xml file – DIGITAL JEDI Jan 12 '16 at 05:32
  • check updated answer @Burhan – Amit Vaghela Jan 12 '16 at 06:49
  • 1
    brother you are not understanding my question fully, what you are posting is called theme switching. What i want is that to change color in xml file. i.e colorPrimary=#ea1e63 and i want colorPrimary=#000000. Without adding this in xml file. In short i want to change colorPrimary with java(programatically) at runtime. Tell me is there a method to set colorPrimary at runtime – DIGITAL JEDI Jan 12 '16 at 08:21
  • yourView.setBackgroundColor(Color.parseColor("#fffff")); this what you want @Burhan – Amit Vaghela Jan 12 '16 at 08:27
  • 1
    Please read my question carefully! if i do this yourView.setBackgroundColor(Color.parseColor("#fffff")); than i have to change color of every object one by one. But i change color in xml file than i dont need to instantiate every object. it will save lots of code – DIGITAL JEDI Jan 12 '16 at 10:16
  • 1
    There is always a way to do – DIGITAL JEDI Jan 13 '16 at 03:52
  • i tried helping you but you dont thing that usefull. @Burhan – Amit Vaghela Jan 13 '16 at 04:00
  • 1
    info you told me is already on all forums and i know it, you ask questions on stackoverflow after you find no content according to your problem. – DIGITAL JEDI Jan 13 '16 at 04:05
  • this is what i know and so told you. i have tried to give you best solution but got this result written in answer. @Burhan – Amit Vaghela Jan 13 '16 at 04:13
  • "can't be" is not acceptable answer ;) better write comment with "I don't know". – Pointer Null Feb 01 '17 at 21:24