Snackbar is similar to a toast, used to present information to the user, and to interact with the user, which can display a button to get the user's action. It features the following:
- As a child view of the Android.support.design.widget.CoordinatorLayout, appears at the bottom of the page.
- You can display a string and a button. Toast can only display text and cannot be interacted with by buttons and users
- Supports swipe right gestures: swipe the finger to the right on Snackbar, then close Snackbar
- Support Set a time, timeout auto shutdown snackbar
How to use:
1. Place the parent layout Coordinatorlayout
<android.support.design.widget.coordinatorlayout xmlns:android= "Http://schemas.android.com/apk/res/android" Xmlns:app= "Http://schemas.android.com/apk/res-auto" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" Match_parent " android:layout_height = "Match_parent" android:fitssystemwindows= "true" android:background= "#2a5caa" > </android.support.design.widget.CoordinatorLayout>
2. Perform the display snackbar in the code
Snackbar.make (View, "text", Snackbar.length_long) . Setaction (new View.onclicklistener () { @Override Public void OnClick (View v) { alert ("xxxxx"); } }). Show ();
Complete.
Use of Android Snackbar