Dialog, toast, snackBar reminder for Android Development

Today, I will bring you a simple and easy to understand micro skills article. There are no advanced technical points, but the focus is on the details. I believe it can help many friends.

Dialog and toast are certainly familiar to everyone. We usually use too much. SnackBar is a new control provided in the design support library. Some friends may have used it, and some friends may not understand it. But do you really know when to use dialog, toast and snackBar? Look at the renderings first:

1,Dialog

First, let's introduce the usage of dialog:

The display effect will be different when running on different versions of mobile phones, but since it is a trick, Google has fully considered this, and also provides an alertdialog class in the appcompat-v7 Library:

2,Toast

Let's take a look at the basic usage of toast:

However, if our hands slip and click five times, toast will appear five times. Because it is passive, we can't make it disappear in time; However, the trick I bring you is to encapsulate it with toastutils.java:

Then use in other classes:

3,Snackbar

First, under the app / build.gradle closure:

Then use:

4. Summary

Now you have three ways to prompt users, dialog, toast and snackBar. Let's summarize the use timing of these three ways:

Dialog: use dialog when the prompt is crucial and the user must make a decision before continuing. Toast: toast is used when the prompt just tells the user that something has happened and the user does not need to respond to it. SnackBar: in any scenario other than the above two, snackBar may be your best choice.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>