Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show md-toast with background color

I am trying to create md-toast with having some background color to toast using angular-material. I using answers from this SO question, I created this codepen, but it is showing some unwanted background to toast as well.

HTML:

<div ng-controller="AppCtrl" layout-fill="" layout="column" class="inset toastdemoBasicUsage" ng-cloak="" ng-app="MyApp">
  <p>
    Toast is not properly working with theme defined in CSS.
    <br>
  </p>

  <div layout="row" layout-sm="column" layout-align="space-around">
    <md-button ng-click="showSimpleToast()">
      Toast
    </md-button>
  </div>    
</div>

CSS:

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

md-toast.md-error-toast-theme {
    background-color: maroon;
    position: 'top right'
}

md-toast {
    height: 40px;
    width: 50px;
    margin-left: auto;
    margin-right: auto;
    left: 0; right: 0;
    top:10px;
}

JS:

angular.module('MyApp',['ngMaterial', 'ngMessages'])
.controller('AppCtrl', function($scope, $mdToast, $document) {
  $scope.showSimpleToast = function() {
    $mdToast.show(
      $mdToast.simple()
        .textContent('Simple lala Toast!')
      .theme('success-toast')
        .hideDelay(3000)
    );
  };
})
like image 635
Saurabh Avatar asked Jan 05 '16 15:01

Saurabh


People also ask

How do you change the background color of a toast message?

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(). getBackground().

How do you make colored toast?

Use a small paint brush and dip the brush into the food coloring. Then take a piece of bread and paint a face or picture of choice on it. Place the bread into a toaster and wait till the bread is lightly toasted. Butter lightly to give taste.

How do I show a toast message in HTML?

How To Create a Toast. To create a toast, use the . toast class, and add a . toast-header and a .

How do you toast with bootstrap?

For setting the toast options via data attributes, just append the option name to data-bs- , such as data-bs-autohide="false" , data-bs-delay="3000" , etc. Apply a CSS fade transition to the toast. Auto hide the toast. Delay hiding the toast (ms).


1 Answers

.toastClass(string) Sets a class on the toast element

Define css:

.md-toast-done .md-toast-content{
    background: #004f75 !important;
}

.md-toast-error .md-toast-content{
    background: rgb(193, 30, 23) !important;
}

And define toast:

    $mdToast.show(
        $mdToast.simple()
            .toastClass('md-toast-error')
            .textContent(stringValue)
            .position('bottom right')
            .hideDelay(3000)
    );
like image 159
hurricane Avatar answered Sep 18 '22 12:09

hurricane