You are on page 1of 3

After studying this module, you as a future IT Toast is used to show a notification for a particular

professional should be able to: duration. It does not block user from any other
interaction because it disappears on the screen
 Use toast, snackbars and dialogs in notifying
depending on the selected duration. There are two
users with their interaction to the application
durations that can be used in toast. These are the
 Appreciate the use of dependencies to create
user-friendly interfaces following:

LENGTH_SHORT- displays the view for a short time

LENGTH_LONG- displays the view for a slightly


longer duration than the previous

Below is the syntax when using the toast.


 Toast
 Snackbar
 Dialog
Toast.makeText
(context, text to be displayed, duration).show();

Ex.
Toast.makeText(getApplicationContext,
Mobile applications are made to have an interaction “Welcome to your New Journey”, Toast.LENGTH_LONG)
between the user and the device. It can be a .show();
productivity application or a game. These
applications notify users of their engagement in the
application.

In this module, you will learn the 3 types of


components that can be used for notifying users
namely toast, snackbar, and dialog. You will be For the Snackbar, we will be using the Material
guided on how you can utilize these in your mobile Design of Google. To implement this, type
applications. “material.io” in your browser. In the Components Tab,
open source code for Android. Under the Popular
section, click “Get Started with MDC for Android”.
Copy the library and paste it on the dependencies
section of your Android project. Make sure to change
the version with the most current one from the
Google Maven Repository or MVN Repository.
When using different mobile applications, on what
way do you want to be notified with the things you
are doing inside the applications?
______________________________________________________
______________________________________________________
On your Android Studio, change the theme that you In addition, we can also override the duration and
will be using with any them from the material design animation of the snackbar if we want to customize it.
in the themes.xml under the res folder. Next is to We can use the setDuration() and
create a button that will trigger the displaying of the setAnimationMode() methods to do this.
snackbar and initialize it in your java file. On the
onClick method of the button add the following code. snackbar.setDuration(1000);
Snackbar snackbar = Snackbar.make //duration in millisecond
(view, “Message Here”, Snackbar.LENGTH_LONG);
snackbar.show(); snackbar.setAnimationMode(BaseTransientBottomBar.
ANIMATION_MODE_SLIDE);
//choose between slide and fade
This is the syntax for a simple snackbar. The
difference with the toast is that we can add actions
to snackbar. We can add the following code before
using the .show() method.

snackbar.setAction("GO",new View.OnClickListener() {
Like the snackbar, we will be using the material
@Override
design. After the implementation of the library, create
public void onClick(View view) {
a button for triggering the dialog. Use the code below
//Add code here for the function
for reference.
}
});
MaterialAlertDialogBuilder builder = new
MaterialAlertDialogBuilder(this);

builder.setTitle("Confirmation");
builder.setMessage
("Do you want to proceed with the changes?");

builder.setIcon(R.drawable.ic_baseline_help_center_2
4);
builder.setPositiveButton("YES", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface
dialogInterface, int i) {
//add function here for OK
}
});
builder.setNegativeButton("NO", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface
dialogInterface, int i) {
//add function here for NO
}
});
builder.show();
• We make use of different tools to notify the user
of the interactions made with the application. It
can be a Toast, Snackbar or an AlertDialog.

• Every component has its own way to be


implemented as well as the different methods
that we can use on them.

• Toast can be used so that interaction can’t be


blocked. Snackbars are used like Toast but we
can add an action to it. AlertDialogs are used for
confirmation before proceeding with an action.

Google (2020). Material Design Components.


Retrieved https://material.io/components

Tutorialspoint (2020). Android- Alert Dialog. Retrieved


https://www.tutorialspoint.com/android/andro
id_alert_dialoges.htm

Javatpoint (2020). Android Toast Example. Retrieved


https://www.javatpoint.com/android-toast-
Objective: To apply the use of notification in an example
android application
Androidhive (2017). Android Material Design
Task: As an IT student, you are tasked to modify the Snackbar Example. Retrieved
activity that you have done in the driver’s license https://www.androidhive.info/2015/09/androi
identification card. Make use of the AlertDialog and it d-material-design-snackbar-example/
will be prompted before proceeding to the displaying
of the identification card.

Tools and resources: Android Studio and android Compiled by:


device
JEREMI R. MICUA
Faculty, College of Information
and Technology Education

You might also like