How to change the underline color of selected tab in angular-material?
Asked Answered
I

7

20

I am following tutorial to put md-tabs in the md-toolbar from here. But, My selected indicator tab is same color as the md-primarywhich make it invisible. Please see the image below.

enter image description here

But, when I change the color of the md-tabs to md-accent, it will show the indicator.

enter image description here

How do I change the color of the selected indicator tab?

Here is the code:

<md-toolbar class="md-whiteframe-5dp">
    <div class="md-toolbar-tools">
        <h2>Title</h2>
    </div>

    <md-tabs md-selected="tabs.selectedIndex">
        <md-tab id="tab1" aria-controls="tab1-content">Tab #1</md-tab>
        <md-tab id="tab2" aria-controls="tab2-content">Tab #2</md-tab>
        <md-tab id="tab3" aria-controls="tab3-content">Tab #3</md-tab>
    </md-tabs>
</md-toolbar>

<md-content layout-padding flex>
    <ng-switch on="tabs.selectedIndex" class="tabpanel-container">
        <div role="tabpanel" id="tab1-content" aria-labelledby="tab1" ng-switch-when="0" md-swipe-left="tabs.next()" md-swipe-right="tabs.previous()">
            View for Item #1<br />
            data.selectedIndex = 0
        </div>

    <div role="tabpanel" id="tab2-content" aria-labelledby="tab2" ng-switch-when="1" md-swipe-left="tabs.next()" md-swipe-right="tabs.previous()">
        View for Item #2<br />
        data.selectedIndex = 1
    </div>

    <div role="tabpanel" id="tab3-content" aria-labelledby="tab3" ng-switch-when="2" md-swipe-left="tabs.next()" md-swipe-right="tabs.previous()">
        View for Item #3<br />
        data.selectedIndex = 2
    </div>
    </ng-switch>
</md-content>

By the way, all the color are default.

Inspirational answered 27/11, 2015 at 4:53 Comment(0)
D
32

The simplest way is to change via CSS :

md-tabs.md-default-theme md-ink-bar, md-tabs md-ink-bar {
    color: red !important;
    background-color:red !important;
}

But you can also check the § about theming in the documentation : https://material.angularjs.org/latest/Theming/01_introduction

Sometime the CSS is embedded and generated on the fly in style-tags, if this code doesn't work, try to force the color with !important.

Dav answered 27/11, 2015 at 5:7 Comment(2)
is it possible to change its left and right styles? I want its width to be much smallerBulley
It works, if you're using default theme (aka not using a custom theme)Fallen
C
8
md-tabs md-ink-bar {
    color: green;
    background-color: green;
}
Crafton answered 1/2, 2016 at 9:58 Comment(0)
A
3

Bit late to the party but might help someone. Simply put color property of the mat-tab-group to none

<mat-tab-group mat-align-tabs="start" mat-align-tabs="center" color="none">
Aegir answered 18/6, 2021 at 8:39 Comment(0)
L
2

You need to define a custome theme and set the accent-color to the one that you want your md-ink-bar to have. In this example it's white:

var customAccent = {
    '50': '#b3b3b3',
    '100': '#bfbfbf',
    '200': '#cccccc',
    '300': '#d9d9d9',
    '400': '#e6e6e6',
    '500': '#f2f2f2',
    '600': '#ffffff',
    '700': '#ffffff',
    '800': '#ffffff',
    '900': '#ffffff',
    'A100': '#ffffff',
    'A200': '#fff',
    'A400': '#f2f2f2',
    'A700': '#ffffff'
};
$mdThemingProvider
.definePalette('whiteAccent', customAccent);

$mdThemingProvider.theme('whiteAccentTheme')
    .primaryPalette('deep-purple')
    .accentPalette('whiteAccent');

You can generate an accent-palette on this site: https://angular-md-color.com/#/

In your view, use the new custom theme for your md-tabs:

<div md-theme="whiteAccentTheme">
  <md-tabs class="md-primary">...</md-tabs>
</div>
Limbic answered 3/5, 2016 at 16:55 Comment(0)
R
2

CSS

.mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar {
    background-color: #f44336;                     
}
Rabi answered 22/8, 2019 at 13:15 Comment(1)
The question is for AngularJS Material, not Angular Material.Cohosh
S
1

I had struggle with this issue, too. I don't like the solution to overwrite the CSS. So there is a a much more convenient and more straight forward solution:

Just set the default HUE for your palette:

$mdThemingProvider.theme('default')
            .primaryPalette('amber', { 'default': '600'})
            .accentPalette('indigo', { 'default': '400'});

The tab ink bar, the FAB speedial, ... will use this color from your palette.

Selfgoverned answered 3/5, 2016 at 14:17 Comment(0)
R
0

After much wasted time reading responses that just didn't work, this is the solution I have found. Being new to CSS, and as someone that despises CSS, I thought I would post my solution for those that also are new to CSS and despise CSS.

HTML

<md-tab-group>
    <md-tab>
        <ng-template md-tab-label>
            <span class="mdTab">Tab Label</span>
        </ng-template>
    </md-tab>
</md-tab-group>

CSS

.mdTab{
  color: white;
}
Rondeau answered 24/6, 2017 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.