Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I change the color of Toast depends on message type in Angular material $mdToast?

While using $mdToast.simple().content("some test") it is showing the toast with black color. how can I change that color to red, yellow and so, depends on the type of the error messages like error, warning and success.

Similar question as this.

like image 274
Rafiu Avatar asked Feb 12 '15 15:02

Rafiu


People also ask

How do you change the color of your toast?

If you need to change the position of the Toast on the Screen then you need to set the gravity by using setGravity() function. If you need to change the background of the Toast then you need to use getView(). setBackground() function. If You need to change the color of the view created then you need to use getView().

What is toast message in angular?

The Angular Toast is a small, nonblocking notification pop-up. A toast is shown to users with readable message content at the bottom of the screen or at a specific target and disappears automatically after a few seconds (time-out) with different animation effects.


1 Answers

There is an easier way by specifying a theme:

$mdToast.simple().content("some test").theme("success-toast") 

And in your CSS:

md-toast.md-success-toast-theme {     background-color: green;     ... } 

You could incorporate your message type to dynamically select a theme.

Update: As Charlie Ng pointed out, to avoid warnings regarding use of an unregistered custom theme register it in your module using the theme provider: $mdThemingProvider.theme("success-toast")

Another update: There was a breaking change created on 2 Dec 2015 (v1.0.0+). You now need to specify:

md-toast.md-success-toast-theme {     .md-toast-content {         background-color: green;         ...     } } 
like image 127
rlay3 Avatar answered Sep 18 '22 16:09

rlay3