Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting a View background based on theme attribute crash the app
    primarykey
    data
    text
    <p>I'm trying to set a ListView background color based on the current theme attribute, but it crash every time the ListView is shown.It seems I'm doing something wrong but I can't see what...</p> <p>Here's what I'm doing:</p> <p>First, create the background color:</p> <pre><code>&lt;resources&gt; &lt;color name="userlist_background_light"&gt;#fff0f0f0&lt;/color&gt; &lt;color name="userlist_background_dark"&gt;#ff040404&lt;/color&gt; &lt;/resources&gt; </code></pre> <p>Second, create attributes for my custom themes:</p> <pre><code>&lt;resources&gt; &lt;attr name="userlist_background" format="reference|color" /&gt; &lt;/resources&gt; </code></pre> <p>Third, setting this attribute in my themes:</p> <pre><code>&lt;resources xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;style name="Light" parent="Theme.Sherlock.Light"&gt; &lt;item name="userlist_background"&gt;@color/userlist_background_light&lt;/item&gt; &lt;/style&gt; &lt;style name="Dark" parent="Theme.Sherlock"&gt; &lt;item name="userlist_background"&gt;@color/userlist_background_dark&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre> <p>And finally, using this attribute in the ListView xml:</p> <pre><code>&lt;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" /&gt; </code></pre> <p>Even the Eclipse layout view crash. Of course, it works fine if I use a "@color/" directly in the background attribute. It even work if I use say, "?android:attr/colorBackground". </p> <p>The message error is:</p> <blockquote> <p>android.view.InflateException: Binary XML file line #8: Error inflating class android.view.ListView Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010068 a=-1}</p> </blockquote> <p>I'm pretty sure I'm doing something wrong, as it works with android attributes, but I haven't be able to find what during my Google searches.</p> <p>I hope you'll be able to help me!</p> <p>Many thanks,</p> <p>Sébastien.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload