31

I'm using my own library. In this library I defined some resources:

colors.xml (library)

<color name="colorPrimary">#000000</color>

In my app (that uses the above library). I want to override that color primary.

colors.xml (app)

<color name="colorPrimary">#ffffff</color>

I actually want to override that attribute so that the library (and my app) use the overrided one, not the declared one from library. It works fine but Android Studio keeps yelling out that:

Overriding @color/colorPrimary which is marked as private in my_lib. If deliberate, use tools:override="true", otherwise pick a different name". That makes me think that this is not a good approach.

I also try to add tools:override="true" to the resource:

<resources xmlns:tools="http://schemas.android.com/tools"
       tools:override="true">

but the warning still there.

Is there any wrong with what I'm doing?. I can not pick another name because I want the library to use the overrided values.

I'm using Android Studio 2.1.1 and gradle 2.1.0 version.

Thanks.

Rumit Patel
  • 8,830
  • 18
  • 51
  • 70
Paul
  • 950
  • 2
  • 12
  • 28
  • 1
    how about add `override` attribute to your color element. – Jiang YD May 18 '16 at 03:28
  • You're right, putting the override attribute for each color tag works as expected. Anyway, Is there a way to make the override attribute applied for all color tags without manually setting for each tag? – Paul May 18 '16 at 03:46

1 Answers1

36

Move the tools:override to the color tag.

There's nothing wrong with this. Android Studio is just warning you, incase it wasn't deliberate.

If you press alt-enter on the line with the warning, AS will offer to insert the override attribute for you and will put it in the correct place.

alex
  • 6,359
  • 1
  • 23
  • 21
  • 1
    It works as expected now. Thanks. However, alt-enter seems not to offer to insert the override attribute. – Paul May 18 '16 at 03:49
  • Try hovering over the error highlight, it should tell you the shortcut. – alex May 25 '16 at 01:32