Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change NavBar color for all the pages in ionic

I am new in ionic and wants to learn it. my question is How to change nav bar color for all the pages in ionic 3.

I have been using following code

<ion-header>
  <ion-navbar color="primary">
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Hello Ionic</ion-title>
  </ion-navbar>
</ion-header>

Is there any way to change nav bar color for all the pages instead of manually doing <ion-navbar color="primary">

like image 810
Riddhi Avatar asked Mar 12 '18 08:03

Riddhi


People also ask

How do I change the color of the navigation bar text?

The text color of the navigation bar can be changed using two inbuilt classes: navbar-light: This class will set the color of the text to dark. This is used when using a light background color. navbar-dark: This class will set the color of the text to light. This is used when using a dark background color.

How do I change the color of the ionic 5 menu?

Here is an example of an Ionic 5 menu: To style the Ionic 5 toolbar or top bar you have a bunch of scss variables which are: Just put them in the variables.scss file and change their values to your desired colors. ion-header, ion-content, ion-footer and ion-toolbar make part of every Ionic 5 page so you can either:

How to style the ionic 5 toolbar or top bar?

To style the Ionic 5 toolbar or top bar you have a bunch of scss variables which are: Just put them in the variables.scss file and change their values to your desired colors. ion-header, ion-content, ion-footer and ion-toolbar make part of every Ionic 5 page so you can either:

How to override the inbuilt navigation bar classes?

The names of the classes are kept in a manner to override the inbuilt navigation bar classes. The background color is set by directly specifying the background-color property with the color needed. The navbar text and the brand text color can be set using the .navbar-text and .navbar-brand classes.


2 Answers

Add following line to variables.scss file to change the color globally.

$toolbar-background: #3D9BDD;
like image 86
Ajantha Bandara Avatar answered Sep 22 '22 13:09

Ajantha Bandara


This can achieve different way i will show you 2 way

First way

In variables.scss file $colors portion add customColor

$colors: (
  primary:    #488aff,
  secondary:  #32db64,
  danger:     #f53d3d,
  light:      #f4f4f4,
  dark:       #222,
  customColor:(
    base: #00953B,
    contrast: #ffffff
  )
);

Here base is background color and contrast is text-color

And change in .html file

<ion-header>
  <ion-navbar color="customColor">
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Hello Ionic</ion-title>
  </ion-navbar>
</ion-header>

Second way

override default color toolbar color

$toolbar-background: #00953B;
like image 27
Utpaul Avatar answered Sep 25 '22 13:09

Utpaul