vendredi 8 mai 2015

Change tab indicator color in actionbar

I know this question was asked many times before, but I tried all solutions and nothing is working. So I've decided to follow official documentation: http://ift.tt/18bHaHW

I've made file themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
        parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:actionBarTabStyle">@style/MyActionBarTabs</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
        parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/actionbar_background</item>
    </style>

    <!-- ActionBar tabs styles -->
    <style name="MyActionBarTabs"
        parent="@android:style/Widget.Holo.ActionBar.TabView">
        <!-- tab indicator -->
        <item name="android:background">@drawable/actionbar_tab_indicator</item>
    </style>
</resources>

actionbar_background is just simple shape with solid fill and it's working.
However indicator is still blue:
actionbar_tab_indicator - this is file generated from http://ift.tt/1cN4rFd I've also copy-pasted generated images to drawable folder. First issue was 9-patch files were somehow wrong, but I've managed to manually fix them.

I'm setting theme in AndroidManifest.xml: android:theme="@style/CustomActionBarTheme"

I've also tried solutions for changing color programatically, but it doesn't work as intended. Instead of being small rectangle it's stretched to fit whole tab.

Any solution (programatically or in xml) working in latest android studio will be great. But it must look just like the orginal tab, but with other color - in my case red.

Regards

Aucun commentaire:

Enregistrer un commentaire