Note that there are some explanatory texts on larger screens.

plurals
  1. POUse different Color for different ActionBar.Tab
    primarykey
    data
    text
    <p>I want to have all tabs in ActionBar to have different Color Indicators, for example blue for tab 1, red for tab 2 etc. </p> <p>To achieve that I did create different selectors for all colors and put them in different xmls in drawable. In style.xml I am calling them by </p> <pre><code>&lt;style name="MyTheme" parent="AppBaseTheme"&gt; &lt;item name="android:actionBarTabStyle"&gt;@style/ActionBarTabStyleRed&lt;/item&gt; &lt;/style&gt; &lt;style name="ActionBarTabStyleRed"&gt; &lt;item name="android:background"&gt;@drawable/tab_indicator_red&lt;/item&gt; &lt;/style&gt; </code></pre> <p>I've created that style for different colors too. Now when I change the drawable or style to different color, it works. I can see colors being applied to tabs. But since all tabs are of same color, it didn't solve my purpose. I tried to set style of tabs in <code>onTabSelected()</code> but there's no method to do that. </p> <p>Ultimately I tried to create different themes for different colors and tried to set them programtically in <code>onTabSelected()</code>, but then I got to know that theme must be set before <code>setContentView()</code>.<br> So My questions is..How can I do that? Is there any way I can have different colors for different tab indicators???</p> <p><strong>Update:-</strong><br> the drawable/tab_indicator_red.xml </p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;!-- Non focused states --&gt; &lt;item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" /&gt; &lt;item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_red" /&gt; &lt;!-- Focused states --&gt; &lt;item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_red" /&gt; &lt;item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_red" /&gt; &lt;!-- Pressed --&gt; &lt;!-- Non focused states --&gt; &lt;item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_red" /&gt; &lt;item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_red" /&gt; &lt;!-- Focused states --&gt; &lt;item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_red" /&gt; &lt;item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_red" /&gt; &lt;/selector&gt; </code></pre>
    singulars
    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