Benjamin Owen
Benjamin Owen

Reputation: 618

Android Change Color Resource Value Programmatically

I am making an app and was wondering if there was a way to change a color resource value programmatically. For example, I am using the resource R.color.text_color_name to set the TextView text color. Is there a way to set that value to something different so that it would change the color of every TextView in the application?

Upvotes: 2

Views: 8001

Answers (1)

j2emanue
j2emanue

Reputation: 62519

The R file contains constants, you cant change them at runtime because you can't normally change constants at run time. If you want to update the color of all textviews why dont you look into themes. Create a custom theme and then change the theme when activity loads in onCreate. After you set the new theme i think your going to have to call setContentView again and then call all your findViewByIds again as they will be null. You could also try Calling recreate() after setTheme(). This sounds messy.

Maybe this can help you change the theme.

Upvotes: 1

Related Questions