Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Even though you found a workaround, maybe this will help someone else. I found a simple way to do this in xml (what logcat's answer is referring to). The trick I used was to create custom attributes for my menu/actionbar icons. You have to have one attribute per menu item icon.</p> <p>You need to create <code>attrs.xml</code> in your <code>values</code> folder, and add your custom attributes. Think of each attribute as a constant that your themes/styles set, and then your styles/views can use those contants to set properties.</p> <pre><code>&lt;declare-styleable name="customAttrs"&gt; &lt;attr name="customSearchIcon" format="reference" /&gt; &lt;/declare-styleable&gt; </code></pre> <p>In your <code>styles.xml</code> in your <code>values</code> folder, have your themes/styles that set your custom icon attributes to <code>drawable</code> references.</p> <pre><code>&lt;style name="AppThemeDark" parent="Theme.Sherlock.ForceOverflow"&gt; &lt;item name="customSearchIcon"&gt;@drawable/action_search&lt;/item&gt; &lt;/style&gt; &lt;style name="AppThemeLight" parent="Theme.Sherlock.Light.ForceOverflow"&gt; &lt;item name="customSearchIcon"&gt;@drawable/action_search_light&lt;/item&gt; &lt;/style&gt; </code></pre> <p>Lastly, in your <code>[menu_name].xml</code> in your <code>menu</code> folder, have your menu item set its icon to your matching custom icon attribute.</p> <pre><code>&lt;item android:id="@+id/menuitem_search" android:icon="?attr/customSearchIcon"/&gt; </code></pre> <p>Now, depending on what theme is set, the icon for the menu item will change. Also, this allows you to still have API specific versions of your drawables (light and dark) using resource identifiers with your <code>drawable</code> folders, so you can have different menu style icons for pre 3.0 and actionbar style icons for 3.0+.</p> <p>Also, remember when setting a theme at runtime (vs <code>AndroidManifest.xml</code>), you must set it before calling <code>setContentView()</code> in your <code>Activity</code>. It is recommended to restart your activity after changing the theme of an <code>Activity</code> that has already been created.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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