在操作栏中为向后箭头定义自定义颜色后,会返回一个警告.可以做些什么来摆脱这个警告?
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
解决方法
而不是做穆罕默德的
android { lintOptions { disable 'PrivateResource' } }
我建议您执行以下操作,这是一个声明的本地修复程序.优点是不需要全局禁用lint-checking(稍后可以很容易地忘记再次激活).
对于XML:
tools:ignore="PrivateResource"
代码:
@SuppressLint("PrivateResource")
有效地,您的代码应该看起来像这样:
XML:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:icon="@drawable/abc_ic_search_api_mtrl_alpha" tools:ignore="PrivateResource" />
码:
@SuppressLint("PrivateResource") final Drawable upArrow = ContextCompat.getDrawable(context,R.drawable.abc_ic_ab_back_mtrl_am_alpha);