سؤال

I have some colours which are reused in several different parts of my Android UI design. I am declaring the colours as resources in colors.xml with meaningful names:

<color name="action_bar_background">#1a404f</color>
<color name="edit_heading_background">#1a404f</color>

When I have multiple different definitions for the same colour value (as in the above example), is there a way of specifying the actual value of #1a404f just once? Or do I have to move away from naming the colours semantically, and give them names like dark_blue instead?

هل كانت مفيدة؟

المحلول

You can define one colour in terms of another, like this:

<color name="dark_blue">#1a404f</color>

<color name="action_bar_background">@color/dark_blue</color>
<color name="edit_heading_background">@color/dark_blue</color>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top