Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make color resources private in android?

I was wondering if its possible to have private color resources in android?

Eg: Files in main: colors.xml:

  <color name="red">#520A2A</color>
  <color name="red_darken_1">#A11453</color>

Files in flavor 1: element_colors.xml:

  <color name="header_color">@colors/red</color>
  <color name="footer_color">@color/red_darken_1</color>

Files in flavor 2: colors.xml:

  <color name="blue">#041B3F</color>
  <color name="blue_darken_1">#244B77</color>

element_colors.xml:

  <color name="header_color">@colors/blue</color>
  <color name="footer_color">@color/blue_darken_1</color>

Now I don't want people to use colors in layout files or styles from colors.xml, but I always want them to use it from element_colors.xml so that the app does not become specific to a single flavor. Basically, how to make some color files inaccessible to layouts and styles?

like image 793
Infant Dev Avatar asked Oct 30 '22 11:10

Infant Dev


1 Answers

Yes, you can make resources private for a library.

Please have look at the Documentation.

and specifically, note the trick,

All resources in a library default to public. To make all resources implicitly private, you must define at least one specific attribute as public.

like image 106
Let'sRefactor Avatar answered Nov 15 '22 05:11

Let'sRefactor