How to Create Android Snackbar Using New Android Design Support Library

0
Shares
How to Create Android Snackbar Using New Android Design Support Library
Rate this post

With the release of Android Lollipop 5.0, Google has new introduced a new Android design support library with many tools and widgets such as Android floating Action button, Floating Label Android, Android Snackbar, and many others.With the help of this library, you can use material design tools for the pre lollipop Android devices.

Android Snackbar is basically same as the Android Toast, but with some additional features. This appears at the bottom of the screen and above all other elements of the screen. As said, the Android snackbar is just like Android Toast that has an option for user feedback.

Generally, this widget is used when a user needs an option to reverse the last action like un-doing an action. And, in this Android Snackbar example, we’ll build Android app to demonstrate how to implement snackbar in Android app with both with and without option to undo last action taken.

Let’s Get Started

Open your Android Studio and create new project under file menu.

imagepicker1

In the next tab, select your targeted Android device.

imagepicker2

Add Empty Activity and click on next.

imagepicker3

Lastly, Enter your activity name and details.

imagepicker4

Start Code Integration

Build Gradle

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
}

MapsActivity.Java

final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.cordinatorLayout);

findViewById(R.id.btnSimple).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar snackbar = Snackbar.make(coordinatorLayout, "Simple Snackbar", Snackbar.LENGTH_LONG);
snackbar.show();
}
});
findViewById(R.id.btnCallback).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "Snackbar with Callback", Snackbar.LENGTH_LONG)
.setAction("OK", new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar snackbar1 = Snackbar.make(coordinatorLayout, "Snackbar with Callback called.", Snackbar.LENGTH_SHORT);
snackbar1.show();
}
});
snackbar.show();
}
});

That’s It!

final-output

As you can see, we’ve completely added snackbar in Android app. Though, it’s not looking quite appealing, but you can consult with Android App development company to hire UI/UX designer to create impression user experience for your Android app development project.

 
0
Shares
 

Want to Develop Android App From Ground-Zero? Contact Us Now