Android SnackBar and androidsnackbar
SnackBar is a new control provided in Android Support Library 22.2.0. It is an enhanced version of Toast power.
Advantages:
1. With CoordinatorLayout, the SnackBar can be crossed by the Swipe gesture;
2. The setAction function. You can set a button on the SnackBar. In the Inbox, UNDO is implemented through the setAction of the SnackBar;
Usage:
final Snackbar snackbar = Snackbar.make(coordinatorLayout, "Snack Bar", Snackbar.LENGTH_SHORT); snackbar.setAction("Dismiss", new View.OnClickListener() { @Override public void onClick(View v) { snackbar.dismiss(); } }); snackbar.show();
The usage is very simple, almost no difference with Toast.
The first parameter of the make () method is a view. To Support the Swipe gesture, this view must be a CoordinatorLayout (also a control in the Android Support Library)
SetAction. Its usage is also clear at a glance. Set the display content string and set an OnClickListener.
Note the following when using SnackBar:
1. The view of the first parameter of the make () method cannot be a ScrollView.
Because the implementation logic of SnackBar is to addView to this View, and ScrollView we know that there is only one Child. Otherwise, Exception will occur.
2. if you want to replace Toast with SnackBar. note that the difference between Toast and SnackBar is that the former includes the keyboard suspended on all la s, while the SnackBar directly addView on The View.
Therefore, when using SnackBar. show (), you must first put the Keyboard. hide (). Otherwise, the Keyboard will cover the SnackBar.
3. In Android2.3, the SnackBar uses CoordinatorLayout and does not support the Swipe function.
I personally think that this little flaw can be ignored.
4. In Android2.3, the dark background color of the SnackBar is similar to the font color. You can use SpannableString to change the color of the String to the make () method.