Change tab indicator color in actionbar

Makalele

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: https://developer.android.com/training/basics/actionbar/styling.html

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://jgilfelt.github.io/android-actionbarstylegenerator/ 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

esme_louise

I've always found it easiest to use the tools from the Android Asset Studio, since I'm not particularly graphically inclined. This tool in particular is very relevant to what you're trying to accomplish: http://jgilfelt.github.io/android-actionbarstylegenerator/ . The full suite of tools can be found at http://romannurik.github.io/AndroidAssetStudio/ . Just choose the colors/styles you want, download the zip file, and copy/paste the files into your project. Then in your AndroidManifest.xml file, reference whichever 'Style name' you choose in the generator (the first text box you filled in on the website) in the activity that contains your ActionBar. So for instance if you called your style 'Custom_action_bar' in the generator, you would add it to your activity as follows:

<activity
    android:name="com.company.appname.ActivityName"
    android:label="@string/somename"
    android:theme="@style/Theme.Custom_action_bar">
    <!--the above line is all you need to add-->
</activity>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related