I wanted to provide the SnackBar
animation from top, instead of the regular behavior that displays the SnackBar
from bottom. Is this easily hackable?

- 156,034
- 29
- 297
- 305

- 3,245
- 5
- 26
- 36
4 Answers
it is possible. check this library made by me https://github.com/AndreiD/TSnackBar
basically you add 2 new animations for sliding from top, and change the gravity of the layout. That's all :)
Later Edit: there's a bug going on.... . if anyone wants to spend some time into fixing it we'd all appreciate it :)

- 10,704
- 7
- 55
- 67
-
4Unfortunately your library suffers from a huge bug, in which the TSnackBar will only appear once if you change activity/fragment, so unfortunately it's unusable in production. – Henrique de Sousa Feb 02 '16 at 12:07
-
1@HenriquedeSousa huge..like let's say 100 meters tall ? or huge like 150kg ? .... didn't had time to fix it, but you're welcome to make a PR. – OWADVL Feb 02 '16 at 14:30
-
I'm trying to fix it, but I cannot find the cause, if you know where it is just explain and i'll try to look at it in my spare time, thanks ! – Henrique de Sousa Feb 02 '16 at 15:26
-
open source doesn't ask for more.. we're all doing this in our spare time. but if you "need" this library, and you found a solution it would be great to share it with the rest. – OWADVL Feb 02 '16 at 20:50
-
1No, I just added a simple view to the top of another, empty layout. No animations, no single support. My client won't pay me to investigate it further : – Henrique de Sousa Feb 03 '16 at 10:10
-
i have an issue using the provided library every time i change between fragments and i dismiss it the body of snackbar is dismissing first and after split of a second the shadow of snackbar causing a bad user experience.. – tsiro Apr 10 '16 at 12:46
-
I know. I need some time to fix that ugly bug. If someone manages to do it before me, please kindly make a push req. – OWADVL Apr 10 '16 at 15:57
-
@OWADVL What bug does it have? I did not face any issue while using this lib. But my use case was very small one. I would like to know what issue other people are talking about and possibly fix it if I can. So, can you please tell me what the issue is and how to reproduce that issue? – Ashish Pathak Jun 21 '16 at 11:50
-
its returning a exception that is "Could not find class 'android.graphics.drawable.VectorDrawable', referenced from method com.androidadvance.topsnackbar.TSnackbar.getBitmap" – Basant Mar 03 '18 at 06:10
-
1@HenriquedeSousa I solved that by using a singleton class and create a new snackbar everytime. Works fine for me now. I can share the code if anyone's interested. – b-fg Apr 30 '18 at 13:35
-
Yep, you should create your own answer and get the karma upvotes :) – Henrique de Sousa May 11 '18 at 10:13
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
Snackbar snackbar = Snackbar.make(coordinatorLayout, "Text", Snackbar.LENGTH_LONG);
View view = snackbar.getView();
CoordinatorLayout.LayoutParams params =(CoordinatorLayout.LayoutParams)view.getLayoutParams();
params.gravity = Gravity.TOP;
view.setLayoutParams(params);
snackbar.show();

- 609
- 2
- 7
- 2
-
I have been trying to get this to work for over 48 straight hours. I know it is discouraged to do this, but as someone exhausted from trying everything I found before, thank you, thank you very much. Your solution was the only one that worked for me. – Shadow Jul 05 '17 at 08:42
-
It can move the view to top but animation is still from bottom to up, right? – Usman Rana Jun 29 '18 at 13:50
-
1
No it is not possible. The documentation states that
They show a brief message at the bottom of the screen on mobile and lower left on larger devices. Snackbars appear above all other elements on screen and only one can be displayed at a time.
You could use a third part library, like Crouton for instance

- 156,034
- 29
- 297
- 305
EDIT: This solution renders Snackbar on top, but animation is from bottom.
It is possible, at least with Android Material library and a little trick. You can bind snackbar to a view that renders on top position like this:
On activity_main.xml
:
<!-- rest of the components here -->
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/top_coordinator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"/>
On MainActivity.kt
:
val snackbar = Snackbar.make(
findViewById(R.id.top_coordinator),
"Hello World",
Snackbar.LENGTH_INDEFINITE
)
snackbar.show()

- 94
- 1
- 8

- 820
- 7
- 14