How can you adjust Android SnackBar to a specific position on screen

It is possible to set the location that the Snackbar is displayed by positioning a android.support.design.widget.CoordinatorLayout within your existing Activity layout. For example, say your existing layout is a RelativeLayout you could add a CoordinatorLayout as follows: <android.support.design.widget.CoordinatorLayout android:layout_width=”match_parent” android:layout_height=”200dp” android:id=”@+id/myCoordinatorLayout” android:layout_alignParentTop=”true” android:layout_alignParentLeft=”true” android:layout_alignParentStart=”true”> </android.support.design.widget.CoordinatorLayout> Then, make sure you pass the CoordinatorLayout as the first … Read more

Snackbar action text color not changing

The argument of setActionTextColor is the int that represents the color, not the resource ID. Instead of this: .setActionTextColor(R.color.yellow) try: .setActionTextColor(Color.YELLOW) If you want to use resources anyway, try: .setActionTextColor(ContextCompat.getColor(context, R.color.color_name)); Note: To use ContextCompat, I assume you have included Support library to your build.gradle file (It is optional if you have already appcompat (v7) … Read more

How to move a view above Snackbar just like FloatingButton

I’m going to elaborate on the approved answer because I think there’s a slightly simpler implementation than that article provides. I wasn’t able to find a built-in behavior that handles a generic moving of views, but this one is a good general purpose option (from http://alisonhuang-blog.logdown.com/posts/290009-design-support-library-coordinator-layout-and-behavior linked in another comment): import android.content.Context; import android.support.annotation.Keep; import … Read more

Testing Snackbar show with Espresso

This worked for me, please try. onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(“My text”))) .check(matches(isDisplayed())); If you use AndroidX, please use the following: onView(withId(com.google.android.material.R.id.snackbar_text)) .check(matches(withText(R.string.whatever_is_your_text)))

How to show Snackbar at top of the screen

It is possible to make the snackbar appear on top of the screen using this: Snackbar snack = Snackbar.make(parentLayout, str, Snackbar.LENGTH_LONG); View view = snack.getView(); FrameLayout.LayoutParams params =(FrameLayout.LayoutParams)view.getLayoutParams(); params.gravity = Gravity.TOP; view.setLayoutParams(params); snack.show(); From the OP: I had to change the first line: Snackbar snack = Snackbar.make(findViewById(android.R.id.content), “Had a snack at Snackbar”, Snackbar.LENGTH_LONG);

Making a Snackbar Without a View?

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() Snackbar.make(mapFragment.getView(), “Click the pin for more options”, Snackbar.LENGTH_LONG).show(); Find Root View From this answer, there’s a way to get the root view via: getWindow().getDecorView().getRootView() So, maybe, you can do: Snackbar.make(getWindow().getDecorView().getRootView(), “Click … Read more

Move snackbar above the bottom bar

With the material components library you can use the setAnchorView method to make a Snackbar appear above a specific view. In your case if you are using a BottomAppBar and a fab, you should define the fab in the setAanchorView. Something like: FloatingActionButton fab = findViewById(R.id.fab); Snackbar snackbar = Snackbar.make(view, “Snackbar over BottomAppBar”, Snackbar.LENGTH_LONG); snackbar.setAnchorView(fab); … Read more