2015-02-05 69 views
0

我得到的資源未發現異常資源異常SwipeRefreshLayout ProgressBackground

android.content.res.Resources$NotFoundException: Resource ID #0xffff0000 

執行此操作時:

swipeLayout.setProgressBackgroundColor(getResources().getColor(R.color.red)); 

雖然我有這個在colors.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
     <color name="red">#FF0000</color> 
</resources> 

我從我的項目中使用R(而不是android.R)

搖籃:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     applicationId "xxx" 
     minSdkVersion 11 
     targetSdkVersion 18 
    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
     } 
    } 
} 

dependencies { 
    compile 'com.android.support:appcompat-v7:21.0.3' 
    compile 'com.google.code.gson:gson:2.3' 
    compile 'com.mcxiaoke.volley:library:1.0.6' 
    compile 'com.android.support:support-v4:21.0.3' 
} 

任何想法解決這一問題?

+0

檢查是否導入了正確的R,如果是的話嘗試清理項目。 – domi 2015-02-05 22:34:42

回答

1

setProgressBackgroundColor方法的參數應該是顏色資源ID,而不是表示顏色的整數。像這樣使用它:

swipeLayout.setProgressBackgroundColor(R.color.red); 
+0

Android Studio說,採用整數形式的顏色的方法應該傳遞RGB三元組,而不是實際的顏色資源ID。您必須調用getResources.getColor(資源)。但現在應用程序正在用swipeRefresh紅色背景運行。 – David 2015-02-05 22:40:23

+0

我想這是Google支持庫上的一個錯誤。爲整數參數提供「類型檢查」的註釋最近被引入,並且似乎該方法參數被錯誤地註釋。如果您尚未完成此操作,請嘗試將支持庫更新至最新版本(21.0.3) – LukaCiko 2015-02-05 22:46:41

+0

問題仍然存在請檢查我的gradle。 – David 2015-02-05 22:57:32