自定義控件裏面使用自定義屬性,出現錯誤Can't convert value at index 0 to color: type=0x5

首先背景是eclipse的項目轉到Androidstudio上來,as的版本是3.0以上的,然後新建項目,複製粘貼xxx的,首先出了個問題,佈局文件說有錯,需要正確build才行,有毒,坑的很,重啓as才搞定。(對了,因爲新版的as新建佈局,都是用的constrantlayout,我是改了系統樣式,刪掉constant的依賴包然後重啓as)然後裝app,發現報錯。

Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 0 to color: type=0x5
        at android.content.res.TypedArray.getColor(TypedArray.java:496)
        at com.fingerfun.a8h5yap.LineProgressBar.<init>(LineProgressBar.java:28)

我第一反應是自定義屬性拿不到?

xmlns:custom="http://schemas.android.com/apk/res-auto"

命名空間哈,custom:lineColor="#FFCC00"控件使用哈。

https://stackoverflow.com/questions/46847724/java-lang-unsupportedoperationexception-cant-convert-value-at-index-5-to-color/46950028#46950028

非常好這篇文章啓發了我,擦

刪掉命名空間,用代碼去設置,程序是可以跑了,。然而還是有一些問題,先不管,做個記錄。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章