我想設置一個基於當前主題屬性的ListView背景顏色,但它每次顯示ListView時都會崩潰。看起來我做錯了什麼,但是我什麼也看不見......基於主題屬性設置視圖背景崩潰的應用程序
下面是我在做什麼:
首先,創建背景色:
<resources>
<color name="userlist_background_light">#fff0f0f0</color>
<color name="userlist_background_dark">#ff040404</color>
</resources>
其次,我的自定義主題創建屬性:
<resources>
<attr name="userlist_background" format="reference|color" />
</resources>
第三,在我的主題設置此屬性:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Light" parent="Theme.Sherlock.Light">
<item name="userlist_background">@color/userlist_background_light</item>
</style>
<style name="Dark" parent="Theme.Sherlock">
<item name="userlist_background">@color/userlist_background_dark</item>
</style>
</resources>
,最後使用在ListView XML這個屬性:
<ListView
android:id="@+id/user_bar"
android:layout_width="0dip"
android:layout_height="0dip"
android:background="?attr/userlist_background"
android:cacheColorHint="?userlist_background"
android:visibility="gone" />
即使是Eclipse的佈局來看崩潰。當然,如果我在背景屬性中直接使用「@ color /」,它可以正常工作。它甚至工作,如果我使用說,「?android:attr/colorBackground」。
消息錯誤是:
android.view.InflateException:二進制XML文件行#8:錯誤 充氣類android.view.ListView所致: android.content.res.Resources $ NotFoundException :資源不是 可繪製(顏色或路徑)的TypedValue {T = 0×2/d = 0x7f010068 A = -1}
我敢肯定,我做錯了什麼,因爲它與Android版屬性,但我無法在Google搜索過程中找到它。
我希望你能幫助我!
非常感謝,
Sébastien。
您是否在清單中添加主題? – Luksprog 2012-08-12 07:53:57
是的:)其實,我有一些其他屬性,我從代碼查詢,它運作良好。我只需要有這個工作從XML ... – 2012-08-12 11:30:54
我已經運行你的代碼,它的工作完美無瑕,所以你的代碼中必須有別的東西。您是否嘗試重新啓動Eclipse並清理該項目? – Luksprog 2012-08-12 12:05:54