0

I want to modify the value of a color in colors.xml, such as

<color name="colorPrimary">#3D3D3D</color>. I want to change this using Java programatically so I can modify this while the app is running.

I have tried things like R.color.colorPrimary = "#FFFFFF"; but this throws an incompatable types error because R.color.primary must be set to a int, not a String.

How do I change the colors.xml data using Java?

1
  • 2
    This is not possible to change static resource such as color.xml at runtime Commented Jan 6, 2020 at 17:17

2 Answers 2

1

you can't change these values while the app is running, instead, make two colors in colors.xml and then you can access them using JAVA getResources().getColor(R.id.colorPrimary) or if you want to change the theme colors you can make different themes with different colors and change between them in runtime, more info in here

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to change the color a component, you only need to put the next code

bbbb.setTextColor(ContextCompat.getColor(context!!, int codecolor))
ccc.setBackgroundColor(ContextCompat.getColor(context!!, int codeColor))

1 Comment

You have the reason, i didn't understood the question well, but you cant change the values of resources, only you can modify the components or assign new color

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.