Reputation: 659
I want to change some button colors globally in my code. I cannot seem to fine a way to define a color variable and then assign a color value to that variable.
I tried this Color SelectedColor = new Color();
f1.setBackgroundColor(Color.rgb(0, 0, 100));
I want to use ColorSelected in place of the RGB value so I can edit the value at start up.
f1.setBackgroundColor(Color.ColorSelected);
Upvotes: 21
Views: 47497
Reputation: 764
You must add attribute type="color"
in the color tag:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color type="color" name="menu_background">#666666</color>
</resources>
So, you can use the color in xml file as "@color\menu_background"
and also from java code.
Upvotes: 5
Reputation: 17304
"I cannot seem to fine a way to define a color variable and then assign a color value to that variable."
Here is how you can define a color variable:
int selectedColor = Color.rgb(0, 0, 100);
and use it:
f1.setBackgroundColor(selectedColor);
Upvotes: 11
Reputation: 157487
you can use values/colors.xml
. For instance
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="menu_background">#666666</color>
</resources>
Upvotes: 38