SwipeRefreshLayout setProgressBackgroundColor()给出了奇怪的异常
当我尝试通过setProgressbackground()方法来改变我的SwipeRefresh-进度的颜色我得到的错误:SwipeRefreshLayout setProgressBackgroundColor()给出了奇怪的异常
E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
at android.content.res.Resources.getValue(Resources.java:1026)
at android.content.res.Resources.getColor(Resources.java:756)
at android.support.v4.widget.CircleImageView.setBackgroundColor(CircleImageView.java:118)
at android.support.v4.widget.SwipeRefreshLayout.setProgressBackgroundColor(SwipeRefreshLayout.java:454)
我调用该方法是这样.setProgressBackgroundColor(getResources ().getColor(R.color.mycolor))。颜色存在于资源文件中,并在其他代码中运行良好。
然后我看着SwipeRefreshLayout文件,发现是这样的方法:
/**
* Set the background color of the progress spinner disc.
*
* @param colorRes Resource id of the color.
*/
public void setProgressBackgroundColor(int colorRes) {
mCircleView.setBackgroundColor(colorRes);
mProgress.setBackgroundColor(getResources().getColor(colorRes));
}
和对我来说似乎很奇怪的是,它会调用.setBackgroundColor()一次只整数colorRes和另一次用getResources()。getColor(colorRes)。
我在做什么错?
参数setBackgroundColor
以十六进制形式呈现颜色,而不是资源ID。
颜色与/res/colors.xml
文件加载,可以被称为例如:
setBackgroundColor(getResources().getColor(R.color.red));
,用含有如下/res/values/colors.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
</resources>
这就是我通过调用getResources()。getColor(R.color.mycolor)其中mycolor是我在/ res/values中实现的颜色/color.xml – 2015-01-04 14:18:17
只是pa在运行时发出R.color.mycolor给出错误 – 2015-01-04 14:18:45
您是否已将正确的'R'导入显示错误的类中?你想'com.yourapps.package.R'而不是'android.R' – 2015-01-04 14:21:44
看看这个修复您的问题:HTTP://计算器。 com/questions/26820081/why-setprogressbackgroundcolor-can-not-resolve-error – 2015-01-07 14:13:25