Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

390
Visualizações
How to change background color and font color on selection in mAngular material toggle button

I am facing one issue. I need to change the background color and its font color when user will select the toggle button using Angular material. I am explaining my code below.

 <div class="btn-group">
            <mat-button-toggle-group #group="matButtonToggleGroup" [value]="selectedVal" (change)="onValChange(group.value)" color="primary">
              <mat-button-toggle value="option1" style="border-right: none;width:127px">
                Option 1
              </mat-button-toggle>
              <mat-button-toggle value="option2" style="border-right: none;width:127px">
                Option 2
              </mat-button-toggle>
            </mat-button-toggle-group>
          </div>

The css code is given below.

:host .mat-button-toggle-group{
    border-radius: 20px !important;
    height: 40px !important;
    align-items: center !important;
    margin-top: 5px !important;
    padding: 0 5px !important;
    z-index: 3 !important;
    color: #017cad !important;
}
:host .mat-button-toggle-checked {
    background-color: #017cad !important;
    color: #f5f5f6;
}

As per my code the view looks like below.

image1

When I am selecting any one button it looks like below.

image2

If we see the above view then the some part of background is not filled with the color and also the text color I need to change to white after selection. The right view should looks like below.

image3

I need like above image the angular material toggle button should visible. Please help me to resolve this issue.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I would suggest using themes. With material theming you can extract whichever individual palettes you need from the theme and apply the backgrounds default-contrast color to the text color to achieve optimal contrast with light or dark colors. https://stackoverflow.com/a/48159346/15439733

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda