Change colour navbar header Ionic 2

六月ゝ 毕业季﹏ 提交于 2019-12-19 06:45:27

问题


I have this problem... My colour is white right now, my code is like this:

<ion-header >
  <ion-navbar>
    <ion-title>
      HELLO
    </ion-title>
  </ion-navbar>
</ion-header>

Change color with this opcion is easy (primary, secondary, danger, light, dark)

<ion-header >
      <ion-navbar danger>
        <ion-title>
          HELLO
        </ion-title>
      </ion-navbar>
 </ion-header>

but my problem is when I want to use custom colors. Somebody know how can I resolve it? Thanks inadvance.

Best regards.


回答1:


There're two ways of doing this, based on if you want to change the color only in a single page, or if you want to change it in all the pages from your app:

1) Change it in a single page/view

Just like you can see here

To change the theme, just tweak the $colors map in your src/theme/variables.scss file:

$colors: (
  // ...
  newcolor:    #55acee

)

And then use it in the view

 <ion-header>
      <ion-navbar color="newcolor">
        <ion-title>
          HELLO
        </ion-title>
      </ion-navbar>
 </ion-header>

2) Change it in all the pages/views

In this case, you'd need to add the following in your variables.scss file to override Ionic's defaults:

$toolbar-ios-background: #55acee;
$toolbar-md-background: #55acee;
$toolbar-wp-background: #55acee;

Edit

Hi, how can I add gradient in app/theme/app.variables.scss?

You could add the colors that you're going to use in the src/theme/variables.scss:

$header-first-color: #AAAAAA;
$header-last-color: #000000;

And then set a rule to use it (in your app.scss file if you want to apply it to every page, or in the page-name.scss file if you want to apply it to a single page):

ion-header {
    .toolbar-background {
        background: linear-gradient(135deg, $header-first-color 0%, $header-last-color 100%);
    }
}



回答2:


Might be better to overwrite the ionic variable in your variables.scss file

So you can create a custom color variable

 $new-color:#55acee;

and then pass it into the ionic variable

$toolbar-ios-background:($new-color);
$toolbar-md-background($new-color);
$toolbar-wp-background($new-color);

you can find all the ionic variables here



来源:https://stackoverflow.com/questions/39203937/change-colour-navbar-header-ionic-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!