My Life with Android
Introduction Android Componets UserInterface Advanced UI Data Storage Advanced Concepts Others New Studio


Snackbars are just like Toast messages except they provide action to interact with. Snackbar will be displayed at the bottom of the screen and can be swiped off in order to dismiss them.

1. Simple Snackbar
Normally passing CoordinatorLayout as view param is the best option as it allows Snackbar to enable some features like swipe-to-dismiss and automatically moving of widgets like FloatingActionButton.
And the duration should be LENGTH_SHORT, LENGTH_LONG or LENGTH_INDEFINITE. When LENGTH_INDEFINITEM is used, the snackbar will be displayed indefinite time and can be dismissed with swipe off.
Snackbar.make(mDrawerLayout, "Your message", Snackbar.LENGTH_SHORT)
    .setAction("UNDO", this)

2. Snackbar with Action Callback
You can also mention a callback interaction method using setAction() method. This allows us to take certain action when user interacts with the snackbar.
Snackbar snackbar = Snackbar
        .make(coordinatorLayout, "Message is deleted", Snackbar.LENGTH_LONG)
        .setAction("UNDO", new View.OnClickListener() {
            public void onClick(View view) {
                Snackbar snackbar1 = Snackbar.make(coordinatorLayout, "Message is deleted!", Snackbar.LENGTH_SHORT);

3. Customizing the Snackbar View
Snackbar comes with default white color text and #323232 background color. You can override these colors as mentioned below.
Snackbar snackbar;  
public void submit(View view) {
       // Toast.makeText(getApplicationContext(),"Hai",Toast.LENGTH_LONG).show();
         snackbar = Snackbar
                .make(view, "No internet connection!No internet connection!No internet connection!", Snackbar.LENGTH_LONG)
                .setAction("RETRY", new View.OnClickListener() {
                    public void onClick(View view) {

// Changing message text color

// Changing action button text color
        View sbView = snackbar.getView();
        TextView textView = (TextView) sbView.findViewById(;

Floating Action Button

Scrolling Techniques

During this year's Google I/O, however, Google introduced the Android Design Support Library to make the adoption of Material Design easier. This lets developers focus on the features that make their applications unique.

1. Regions
Before we start, you should familiarize yourself with the available scrollable regions in an Android application. In the following image, you can see that there are four regions.

a. Status Bar
This is where notifications appear and the status of different features of the device are displayed.
b. Toolbar
The toolbar was formerly known as the action bar. It is now a more customizable view with the same functionalities.
c. Tab/Search Bar
This optional region is used to display the tabs that categorize the content of your application.
d. Flexible Space
This is where you can display images or extended app bars.
With regards to scrolling techniques, it's the toolbar and the tab/search bar that respond when the content of your application is scrolling.

Scrolling Technique 1

This technique hides the toolbar region when your application's content is being scrolled.
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >
i. CoordinatorLayout
This layout is a new container and a supercharged FrameLayout that provides an additional level of control over touch events between child views.
i. AppBarLayout
This layout is another new container, designed specifically to implement many of the features of the Material Design app bar concept. Keep in mind that if you use it within another ViewGroup, most of its functionality won't work.
To enable this technique, the app:layout_behavior attribute indicates which view will trigger the events in the Toolbar. In this case, that's the RecyclerView.

The app:layout_scrollFlags attribute of the Toolbar indicates to the view how to respond.
The app:layout_scrollFlags attribute can have four possible values, which can be combined to create the desired effect:
a. scroll
This flag should be set for all views that need to scroll off-screen. Views that don't use this flag remain pinned to the top of the screen.

b. enterAlways
This flag ensures that any downward scroll will cause this view to become visible, enabling the quick return pattern.

c. enterAlwaysCollapsed
When a view has declared a minHeight and you use this flag, the view will only enter at its minimum height (collapsed), only expanding to its full height when the scrolling view has reached its top.

d. exitUntilCollapsed
This flag causes the view to scroll off-screen until it is collapsed (its minHeight is reached) before exiting.

Scrolling Technique 2

This technique scrolls the toolbar off-screen while the tab bar region stays anchored to the top.