Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd like to qualify with "I have not checked this using ActionBarSherlock only the standard actionbar"</p> <p>That said I know this will work on the standard actionbar and see no reason why it would not in ActionBarSherlock.</p> <p>In the onCreate of the activity I have (I'm using the logo attribute but it will work for MenuItems as well)</p> <pre><code> getActionBar().setLogo(R.drawable.logo); getActionBar().setDisplayUseLogoEnabled(true); getActionBar().setHomeButtonEnabled(true); </code></pre> <p>In logo.xml I have a selector</p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true" android:drawable="@drawable/logopressed"/&gt; &lt;item android:drawable="@drawable/logonotpressed" /&gt; &lt;/selector&gt; </code></pre> <p>In logopressed.xml A layer list can be used to make the background</p> <pre><code>&lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:drawable="@android:color/holo_purple" /&gt; &lt;item android:drawable="@drawable/logo_normal" /&gt; &lt;/layer-list&gt; </code></pre> <p>In logonotpressed.xml switch out the background colour and/or icon drawable as desired</p> <pre><code>&lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:drawable="@android:color/white" /&gt; &lt;item android:drawable="@drawable/logo_inverted" /&gt; &lt;/layer-list&gt; </code></pre> <p>So the crux of this solution is to set the selector drawable and let it select a whole new drawable for each state rather than setting a selector drawable to the background attribute of a otherwise static variable</p> <p>Note: you should be able to theme the items with a background instead of doing 2 layers but I haven't been able to get this to work</p>
 

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