Note that there are some explanatory texts on larger screens.

plurals
  1. POOverriding referenced style attributes
    primarykey
    data
    text
    <p>After reading through <a href="http://developer.android.com/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes" rel="noreferrer">References To Theme Attributes</a> I am trying to reference the value of an attribute in the my custom theme that I have set.</p> <p>I am applying a user-defined style to a <code>CheckedTextView</code></p> <pre><code>&lt;CheckedTextView android:id="@+id/contactInfo" style="@style/ListViewCheckedTextViewRowStyle" &gt; &lt;/CheckedTextView&gt; </code></pre> <p>The user-defined style is defined as :</p> <pre><code>&lt;style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle"&gt; &lt;item name="android:checkMark"&gt;?android:listChoiceIndicatorMultiple&lt;/item&gt; &lt;/style&gt; </code></pre> <p>My theme I created is defined as :</p> <pre><code>&lt;style name="Theme.Yellowgreen" parent="android:Theme.Holo.Light.DarkActionBar"&gt; &lt;item name="android:listChoiceIndicatorMultiple"&gt;@drawable/btn_check_holo_light&lt;/item&gt; &lt;/style&gt; </code></pre> <p>However, the checkMark styling that gets displayed is the device's default theme's drawable and not my user defined drawable. </p> <p>The only way I can have my drawable displayed is with :</p> <pre><code>&lt;style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle"&gt; &lt;item name="android:checkMark"&gt;@drawable/btn_check_holo_light&lt;/item&gt; &lt;/style&gt; </code></pre> <p>But that defeats the whole purpose of overriding this attribute, especially since I would like to override this attribute in multiple themes.</p> <p>I am setting the theme in the <code>onCreate()</code> method of my <code>Activity</code> like this:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { this.setTheme(R.style.Theme_Yellowgreen); super.onCreate(savedInstanceState); // ... } </code></pre> <p>I also tried to set the theme in the AndroidManifest.xml file like :</p> <pre><code>&lt;application android:theme="@style/Theme.Yellowgreen" &gt; </code></pre> <p>But that didn't work. What could be going wrong?</p> <h1>Update</h1> <p>I just created a small sample project and it looks like the code i posted above is working. So i must have some other styles which are overriding this property or perhaps it has to do with my layout xml files. </p> <p>In my large project, I have two <code>Fragments</code> within an <code>Activity</code>. Both <code>Fragments</code> have <code>Listviews</code> backed by <code>Adapters</code>. In <code>Fragment A</code> the <code>getView()</code> method of the <code>Adapter</code> is as follows:</p> <pre><code>public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(R.layout.contact_entry, null); } //... return convertView; } </code></pre> <p>In <code>Fragment B</code> the <code>getView()</code> method of the <code>Adapter</code> is as follows:</p> <pre><code>public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(R.layout.list_item, parent, false); } //... return convertView; } </code></pre> <p>The layouts are defined as follows:</p> <p><strong>list_item.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list_item" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;include layout="@layout/list_item_header" /&gt; &lt;include layout="@layout/contact_entry" /&gt; &lt;View android:id="@+id/list_divider" android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:drawable/divider_horizontal_dark" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>list_item_header.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/header_text" android:layout_width="match_parent" android:layout_height="25dip" android:background="@color/dark_blue" android:gravity="center_vertical" android:paddingLeft="6dip" android:textColor="@color/white" android:textSize="14sp" android:textStyle="bold" /&gt; </code></pre> <p><strong>contact_entry.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/contactEntry" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:orientation="horizontal" &gt; &lt;QuickContactBadge android:id="@+id/contactPic" style="@style/ContactPicStyle" /&gt; &lt;CheckedTextView android:id="@+id/contactInfo" style="@style/ListViewCheckedTextViewRowStyle" &gt; &lt;/CheckedTextView&gt; &lt;/LinearLayout&gt; </code></pre> <p>For some reason, in <code>Fragment B</code> the themed checkMark attribute is not rendering correctly whereas in <code>Fragment A</code>, the checkMark uses the current YellowGreen Theme and is styled correctly. Why would this be happening?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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