An overview of the

Snackbar is similar to Toast. It is used to present information to users and interact with them. It can display a button to get the user’s actions. Its characteristics are as follows:

  • It as android. Support. The design. The widget. CoordinatorLayout child views, appear in the bottom of the page.
  • You can display a string and a button. Toast can only display text and cannot interact with users through buttons
  • Support right swipe gesture: Slide your finger right on the Snackbar to close the snackbar
  • Support for setting a time, timeout automatically shut down the snackbar

Usage:

1. Place the parent layout

<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>
Copy the code

2. Execute the display snackbar in the code

Snackbar.make(view, "text ", snackbar.length_long).setAction(" operation ", new View.OnClickListener() { @Override public void onClick(View v) { alert("xxxxx"); } }).show();Copy the code

3. Complete