Is it possible to change BackgroundColor of snackbar for ios?

My app uses a snackbar of material-components-ios. I want to change BackgroundColor to blue, but I can't.

So is it possible to change the background color of snackbar?

Answers


You have to hack it. :)

In your pods there is a file called.

MDCSnackbarMessageView.m

there is function like this. I changed the value already to blue. And it will take hex value color code.

- (UIColor *)snackbarBackgroundColor {
   // return MDCRGBAColor(0x32, 0x32, 0x32, 1.0f); //previous grey color
    return MDCRGBAColor(0x10, 0x3F, 0xFF, 1.0f);// blue color
}

Now do, clean and build again. Here is the output.


You don't have to hack it :-)

Since you have added the swift tag to this question, then I'll give an answer with Swift code.

MDCSnackbarMessageView.appearance().snackbarMessageViewBackgroundColor = .green
MDCSnackbarManager.show(MDCSnackbarMessage(text: "Hi there"))

I'm using MaterialComponents version 68.1. If you too, try this:

let message = MDCSnackbarMessage()
message.text = "message"

MDCSnackbarManager.messageTextColor = .white
MDCSnackbarManager.snackbarMessageViewBackgroundColor = .blue
MDCSnackbarManager.show(message)

Need Your Help

thread_local static member template definition: initialisation fails with gcc

c++ multithreading c++14

When a static member in a C++ class is both thread_local and a member template, it doesn't get initialised.