Android SnackBar and androidsnackbar

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.