What are the new features of Android Design Support Library and how to use its Snackbar?

The new Snackbar doesn’t require Android-M. It is inside the new design support library and you can use it today. Just update your SDK add this dependency in your code: compile ‘com.android.support:design:22.2.0’ You can use a code like this: Snackbar.make(view, “Here’s a Snackbar”, Snackbar.LENGTH_LONG) .setAction(“Action”, null) .show(); It is like a Toast. To assign an … Read more

Style SnackBar in theme app

With the Material Components Library you can globally change the snackbar style in your app theme: <style name=”AppTheme” parent=”Theme.MaterialComponents.*”> <!– Style to use for Snackbars in this theme. –> <item name=”snackbarStyle”>@style/Widget.MaterialComponents.Snackbar</item> <!– Style to use for action button within a Snackbar in this theme. –> <item name=”snackbarButtonStyle”>@style/Widget.MaterialComponents.Button.TextButton.Snackbar</item> <!– Style to use for message text within … Read more

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)))