SwipeRefreshLayout在设置背景时给出异常

时间:2015-03-16 11:05:12

标签: android android-5.0-lollipop

我需要将背景颜色设置为swiperefreshlayout

的圆形图像视图

它总是例外:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobile.clubgecko.beta/com.mobile.clubgecko.activities.ClubGeckoBaseActivity}: android.content.res.Resources$NotFoundException: Resource ID #0xfffd6c00
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

我使用了以下但没有运气

swipeRefreshLayout.setProgressBackgroundColor(Color.parseColor("#fd6c00"));

swipeRefreshLayout.setProgressBackgroundColor(context.getResources().getColor(R.color.geckocolor));

2 个答案:

答案 0 :(得分:3)

我在GrepCode上查找了code

453    public void More ...setProgressBackgroundColor(int colorRes) {
454        mCircleView.setBackgroundColor(colorRes);
455        mProgress.setBackgroundColor(getResources().getColor(colorRes));
456    }

他们使用getResources().getColor()来检索颜色。如果提供真实颜色而不是资源ID,则查找失败(根据例外情况)。您必须提供颜色的资源ID。改变

swipeRefreshLayout.setProgressBackgroundColor(context.getResources().getColor(R.color.geckocolor));

swipeRefreshLayout.setProgressBackgroundColor(R.color.geckocolor);

答案 1 :(得分:0)

尝试setProgressBackgroundColorSchemeColor(),不推荐使用setProgressBackgroundColor()

https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html#setProgressBackgroundColor(int)

旧的弃用方法需要资源ID,但您要传递颜色值。