Marked as private warning after changing colour of up arrow

15,046

Solution 1

See Choose resources to make public for the reason.

In short, drawable/abc_ic_ab_back_mtrl_am_alpha is a private resource of appcompat-v7 and is intended to be used only by that library. You should not use it.

If you really want to use it, copy it to your project

Solution 2

Instead of doing Mohammad's

android {
    lintOptions {
        disable 'PrivateResource'
    } 
}

I'd recommend to do the following, which is a local fix for a statement. The advantage is not having to deactivate the lint-checks globally (which can easily be forgotten to activate again later on).

For XML:

tools:ignore="PrivateResource"

For Code:

@SuppressLint("PrivateResource")

Effectively, your code then should look something like this:

XML:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
    tools:ignore="PrivateResource" />

Code:

@SuppressLint("PrivateResource")
final Drawable upArrow = ContextCompat.getDrawable(context, R.drawable.abc_ic_ab_back_mtrl_am_alpha);

Solution 3

It seems it's a bug in android this post form a project member in Android Open Source Project - Issue Tracker

Replying to a similar Issue

The root cause here is that when a library depends on another library, it imports all the resources from any libraries it depends on into its own declared R.txt (in the AAR file).

However, it doesn't include the public.txt declaration from those dependencies, so now it ends up exposing these symbols as declared but not public -- e.g. private.

I'm considering two fix alternatives:

(1) in the resource visibility lookup for a library, remove any symbols imported from a dependency (whether or not that dependency provides visibility information), or

(2) reverse the visibility lookup logic: if we find a symbol as public in any library, consider it public rather than the current logic which says that if a symbol is declared as private anywhere, it is.

I think I'm going with 2; the current logic doesn't make sense when considering the scenario that symbols end up inlined in downstream libraries.

as they said :

The only workaround for now is to turn off the private resource lint check:

    android {
        lintOptions {
            disable 'PrivateResource'
        } 
    }

they are saying it was fixed but I had run through this issue today and I'm using android studio 1.5.1 and gradle 1.5

Share:
15,046

Related videos on Youtube

wbk727
Author by

wbk727

Apparently, this user prefers to keep an air of mystery about them.

Updated on June 15, 2022

Comments

  • wbk727
    wbk727 almost 2 years

    After defining a custom colour for the back arrow in the action bar, a warning is then returned. What can be done to get rid of this warning?

            final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_mtrl_am_alpha);
            upArrow.setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_ATOP);
            actionBar.setHomeAsUpIndicator(upArrow);
    

    The resource @drawable/abc_ic_ab_back_mtrl_am_alpha is marked as private in com.android.support:appcompat-v7

    • PPartisan
      PPartisan over 8 years
      I've seen a few posts regarding issues accessing system drawables after the latest Android Studio update. This doesn't answer your question directly, but I'd recommend this plugin as a means of easily importing Material Design icons to your project.
  • Francis Bacon
    Francis Bacon about 6 years
    I need to override it, why should I copy the resources?
  • Radesh
    Radesh over 5 years
    this is better way