Comprehensive analysis based on custom toast

Toast is generally used to display a line of text. Its usage is relatively fixed:

However, sometimes when you want to use toast to display complex views or even views with pictures, you need to use the custom toast. The custom toast mainly uses the following methods, as shown in the figure:

1. The setview () method is used to display the user-defined view

2. Setgravity() is used to determine the display position of toast

3. Setduration() is used to set the display time of toast. There are only two options, length_ SHORT,LENGTH_ Long, they are all int.

4. Settext() is used to display a text, but it should be noted that settext() and setview() cannot be used at the same time, otherwise an error will occur.

Here is a complete code to see how to implement a custom toast:

Toast_ view.xml:

Activity_ main.xml:

ToastUtil:

MainActivity:

The toastutil tool class above is not well written. You can rewrite your toastutil class yourself.

The above comprehensive analysis based on custom toast is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

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
分享
二维码
< <上一篇
下一篇>>