I am trying to set the background color of the ListView based on the current theme attribute, but it crashes every time the ListView is displayed. It seems I am doing something wrong, but I do not see that ...
That's what I'm doing:
First create a background color:
<resources> <color name="userlist_background_light">#fff0f0f0</color> <color name="userlist_background_dark">#ff040404</color> </resources>
Secondly, create attributes for my custom themes:
<resources> <attr name="userlist_background" format="reference|color" /> </resources>
Thirdly, setting this attribute in my themes:
<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>
And finally, using this attribute in the 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" />
Even displaying the layout view of Eclipse. Of course, it works fine if I use "@ color /" directly in the background attribute. It even works if I use: "? Android: attr / colorBackground".
Message Error:
android.view.InflateException: binary line of XML file # 8: error bloating class android.view.ListView caused by: android.content.res.Resources $ NotFoundException: Resource is not Drawable (color or path): TypedValue {t = 0x2 / d = 0x7f010068 a = -1}
I am sure that I am doing something wrong, since it works with android attributes, but I cannot find that during a Google search.
I hope you can help me!
Thank you very much,
Sebastien.