How can I implement such a snackbar. To have it with round edges and show above fab and was not stretched across the width of the screen
Snackbar like google io 2018 android
1.5k Views Asked by alex At
3
There are 3 best solutions below
1
On
This is part of Recently launched Material Components pack from Google . Probably available on :-
com.google.android.material:material:1.0.0-alpha3
Whereas Its still in alpha . So i am not quite sure whether you can use it in Production or not . I am attaching some links below to go through.
2
On
Use the Snackbar in the Material Components library.
As default it has rounded corners.
Use the setAnchorView method to make a Snackbar appear above a specific view, in your case the fab button.
Snackbar snackbar = Snackbar.make(view, "...", Snackbar.LENGTH_LONG);
snackbar.setAnchorView(fab);
snackbar.show();
Also you can customize the margin using the snackbarStyle attribute in the app theme.
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
....
<item name="snackbarStyle">@style/MySnackbar</item>
</style>
In the snackbar style use the android:layout_margin attribute.
<style name="MySnackbar" parent="@style/Widget.MaterialComponents.Snackbar">
<item name="android:layout_margin">32dp</item>
</style>

Try to adding this dependency.
Then can add Cafe Bar using this code.
If you need more customization visit the documentation here.