Reputation: 763
I try bring the snackbar to the foremost ui.
My case is
Since Android 12, customization with Toast is pretty much limited, so that's why I decide to use snackbar as a primary option.
I realize that the Toast is controlled by the system, so maybe that is why it is always the foremost ui to the user, even if the system ui(such as internet connectivity panel) presents and I want snackbar to follow that exact behavior.
How should i make snackbar the foremost ui??
I feel like when using snackbar, we use view as a parameter to pass, so manupulating this view would make something different, but i couldn't figure it out.
Upvotes: 1
Views: 267
Reputation: 164
View view
in global and initialize them on your onCreate()
calledfunction(View view)
with SnackBar
declaration codeview
which we have already declared globallyUpvotes: 0
Reputation: 3098
No, you cannot do that.
Snackbar will try and find a parent view to hold Snackbar's view from the value given to view. Snackbar will walk up the view tree trying to find a suitable parent, which is defined as a CoordinatorLayout or the window decor's content view, whichever comes first. Official link
It is clearly mentioned that Snackbar will find and use the parent of the given view. So, the view is inaccessible in other applications. However, if you make the view static, it will be leaking and can product memory leak.
Upvotes: 2