java 更改向上箭头的颜色后标记为私人警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32927273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Marked as private warning after changing colour of up arrow
提问by MacaronLover
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
资源@drawable/abc_ic_ab_back_mtrl_am_alpha 在 com.android.support:appcompat-v7 中被标记为私有
采纳答案by lazybug
See Choose resources to make publicfor 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 onlyby that library. You should not use it.
总之,绘制/ abc_ic_ab_back_mtrl_am_alpha是程序兼容性-V7的私有资源,并拟用作仅通过该库。你不应该使用它。
If you really want to use it, copy it to your project
如果你真的要使用它,把它复制到你的项目中
回答by Freisturz
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).
我建议执行以下操作,这是对语句的本地修复。优点是不必全局停用 lint 检查(很容易忘记稍后再次激活)。
For XML:
对于 XML:
tools:ignore="PrivateResource"
For Code:
对于代码:
@SuppressLint("PrivateResource")
Effectively, your code then should look something like this:
实际上,您的代码应该如下所示:
XML:
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);
回答by Mohammad
It seems it's a bug in android this post form a project member in Android Open Source Project - Issue Tracker
这篇文章似乎是 android 中的一个错误,它是 Android 开源项目中的一个项目成员 - 问题跟踪器
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.
这里的根本原因是,当一个库依赖于另一个库时,它会将其依赖的任何库中的所有资源导入到自己声明的 R.txt(在 AAR 文件中)中。
但是,它不包括来自这些依赖项的 public.txt 声明,因此现在它最终将这些符号公开为已声明但不是公共的——例如私有的。
我正在考虑两种修复方案:
(1) 在库的资源可见性查找中,删除从依赖项导入的任何符号(无论该依赖项是否提供可见性信息),或
(2) 反转可见性查找逻辑:如果我们在任何库中发现一个符号是公共的,则将其视为公共的,而不是当前的逻辑,即如果一个符号在任何地方被声明为私有,它就是私有的。
我想我会选择 2;在考虑符号最终内联在下游库中的情况时,当前的逻辑没有意义。
as they said :
正如他们所说:
The only workaround for now is to turn off the private resource lint check:
android { lintOptions { disable 'PrivateResource' } }
目前唯一的解决方法是关闭私有资源 lint 检查:
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
他们说它已修复,但我今天遇到了这个问题,我使用的是 android studio 1.5.1 和 gradle 1.5
回答by fejd
While I prefer to keep the Lint suppressions as close to the source as possible, as it's done in this answer, if that doesn't work it's also possible to list the suppressions in a lint.xml
file located in your app
folder. It would look something like:
虽然我更喜欢将 Lint 抑制尽可能地靠近源,正如在这个答案中所做的那样,但如果这不起作用,也可以在lint.xml
位于您的app
文件夹中的文件中列出抑制。它看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="<issue-id>">
<ignore path="<path-to-source>.<file-extension>"/>
</issue>
Where issue-id is the type you want to suppress, for example UseSparseArrays. Android Studio will also autocomplete this field for you.
其中 issue-id 是您要抑制的类型,例如 UseSparseArrays。Android Studio 还会为您自动完成此字段。