Skip to content
Advertisement

Making a Snackbar Without a View?

I want to show a snackbar as soon as the user opens the Google Maps activity, but the thing is that there’s no views in the activity to use as the first parameter of the activity (in the findViewById() of Snackbar.make()). What do I put there? Here’s the java class code:

JavaScript

Also, here is the activity xml code:

JavaScript

And lastly, here’s the stacktrace error:

JavaScript

Thanks for the help! 🙂

Advertisement

Answer

I see some options… Not sure which one can fix your issue.

Simpliest

SupportMapFragment extends class android.support.v4.app.Fragment. This way, it has a method getView()

JavaScript

Find Root View

From this answer, there’s a way to get the root view via:

JavaScript

So, maybe, you can do:

JavaScript

NOTE: This approach has the side effect mentioned in the comments below:

The message will be shown behind the bottom navigation bar if the following method will be used to get view getWindow().getDecorView().getRootView()

Add a dummy LinearLayout to get the View

Honestly, I’m not sure if this solution is possible. I’m not sure if you can add a LinearLayout above the Maps fragment… I think it is OK but since I never work with Maps API before, I’m not sure.

JavaScript

and then:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement