Summary of toast message display method in Android Development

This paper summarizes the method of toast displaying messages in Android development. Share with you for your reference, as follows:

Android provides a simple toast message prompt box mechanism, which can prompt the user for some information after the user clicks some buttons. The prompted information cannot be clicked by the user, and the toast prompt information will disappear automatically according to the display time set by the user. Toast's prompt information can easily display something you want to display when debugging the program.

There are two ways to create toast

Java code of the first method:

Parameter: context is the context in which toast is displayed, usually the current activity; Resid refers to the data that the display content refers to the resource, which is to specify the displayed message content from the R class; Duration specifies the display time. Toast has length by default_ Short and length_ Long two constants, representing short-time display and long-time display respectively.

Java code of the second method:

The parameters context and duration are the same as the first method. The parameter text can write the message content by itself.

After you create any Toast object with any of the above methods, you can call the method show () to display it.

Set toast display position

There are two methods to set the display position:

Method 1:

The three parameters are expressed respectively (starting point position, horizontal right displacement and vertical downward displacement)

Method 2:

The display position is set in horizontal and vertical percentages, and the parameters are of float type (horizontal displacement positive right negative left, vertical displacement positive up negative down)

Customize toast

The following code can display a toast effect with pictures:

For more Android related content, readers who are interested can view the special topics of this site: activity operation skill summary of Android programming, Android resource operation skill summary, Android file operation skill summary, Android SQLite database operation skill summary, Android JSON format data operation skill summary, Android database operation skill summary Summary of SD card operation methods for Android programming development, introduction and advanced tutorial for Android development, summary of Android view skills and summary of Android control usage

I hope this article will help you in Android programming.

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