Note that there are some explanatory texts on larger screens.

plurals
  1. POUse attributes in selector - Android
    primarykey
    data
    text
    <p>I'm trying to allow the user to set his own color themes. I've managed to accomplish this with</p> <p><strong>attr.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;attr name="extra_light" format="reference" /&gt; &lt;/resources&gt; </code></pre> <p><strong>styles.xml</strong></p> <pre><code>&lt;style name="Green" parent="@style/AppTheme"&gt; &lt;item name="extra_light"&gt;@color/extra_light_green&lt;/item&gt; &lt;/style&gt; </code></pre> <p><strong>colors.xml</strong></p> <pre><code>&lt;resources&gt; &lt;color name="extra_light_green"&gt;#C5E26D&lt;/color&gt; &lt;/resources&gt; </code></pre> <p>This works well for most of the application however I have a selector which previously had</p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true" android:drawable="@color/extra_light_green" /&gt; &lt;/selector&gt; </code></pre> <p><strong>to</strong> </p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true" android:drawable="?attr/extra_light" /&gt; &lt;/selector&gt; </code></pre> <p>Now it crashes. </p> <p>Here's the logcat, any ideas on how to solve this?</p> <pre><code> FATAL EXCEPTION: main android.view.InflateException: Binary XML file line #8: Error inflating class &lt;unknown&gt; at android.view.LayoutInflater.createView(LayoutInflater.java:683) com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) at com.android.internal.policy.impl.MiuiPhoneLayoutInflater.onCreateView(MiuiPhoneLayoutInflater.java:44) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:730) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:755) at android.view.LayoutInflater.rInflate(LayoutInflater.java:816) at android.view.LayoutInflater.inflate(LayoutInflater.java:559) at android.view.LayoutInflater.inflate(LayoutInflater.java:466) at android.view.LayoutInflater.inflate(LayoutInflater.java:419) </code></pre> <p><strong>EDIT</strong></p> <p>Here is where I apply the selector </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginLeft="10dp" android:orientation="horizontal" &gt; &lt;TextView android:id="@+id/row_menu_title" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/selector_item_news" android:gravity="center_vertical" android:padding="10dp" android:text="Medium Text" android:textSize="16sp" /&gt; &lt;/LinearLayout&gt; </code></pre>
    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.
    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