Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 350
Disp Hay Avatar asked Nov 27 '15 04:11

Disp Hay


4 Answers

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.

like image 83
Arnaud Gueras Avatar answered Oct 10 '22 07:10

Arnaud Gueras


md-tabs md-ink-bar {
    color: green;
    background-color: green;
}
like image 36
Dhruvdutt Jadhav Avatar answered Oct 10 '22 06:10

Dhruvdutt Jadhav


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>
like image 26
Martin Cremer Avatar answered Oct 10 '22 06:10

Martin Cremer


CSS

.mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar {
    background-color: #f44336;                     
}
like image 24
Kanan Avatar answered Oct 10 '22 06:10

Kanan