Android class reference-toast

Source: Internet
Author: User

1. inheritance relationship

Java. Lang. Object

| _____ Android. widget. Toast

2. class overview

A toast is a window that contains short messages to remind users. The toast class will help you create and display this window.

When this window is displayed to the user, it is displayed floating on the application. It does not accept focus. You can also make some input during its display. This idea is to try not to interfere with user operations, while still displaying the information you want the user to see. There are two examples of this operation: volume control and short message reminders that are successfully saved.

The easiest way to use this class is to call a static method, which returns a new toast object.

3. Class Constants

Public static final int length_long

It takes a long time to display window or text notifications. This time is customizable.

Constant Value: 1 (0x00000001)

Public static final int length_short

Display window or text notifications in a short time. This time is customizable. This is the default setting.

Constant Value: 0 (0x00000000)

4. PublicConstructor

Public toast (context)

To construct an empty toast object, you must call the setview (View) method before calling the show () method of the toast object.

Parameters:

Context: Specifies the context for short messages. It is usually an application or activity object.

5. PublicMethod

Public void cancle ()

If the toast window is displayed, you can call this method to close the window. If the window is not displayed, it will not be displayed. This method is usually not called, and the window will be hidden by itself after the corresponding time.

Public int getduration ()

Returns the duration of the toast window.

Public int getgravity ()

Obtains the position that the toast window should display on the screen.

Public float gethorizontalmargin ()

Returns the horizontal margin.

Public float getverticalmargin ()

Returns the vertical margin.

Public View getview ()

Returns the view object of the toast window.

Public int getxoffset ()

In pixels, return the offset of the gravity position used by the toast window in the X axis.

Public int getyoffset ()

In pixels, return the offset of the gravity position used by the toast window in the Y axis.

Public static toast maketext (context, int resid, int duration)

Use the resource ID to point to the text to create a standard toast window that contains only textview objects.

Parameters:

Context: the context to be used by the toast window. It is usually an application or activity object.

Resid: the string resource ID to be used, which can be formatted.

Duration: the time when the message is displayed. Length_short or length_long.

Exception: If no resource is found, a resource. notfoundexception exception is thrown.

Public static toast maketext (context, charsequence text, int duration)

Create a standard toast window that only contains text.

Parameters:

Context: the context to be used by the toast window. It is usually an application or activity object.

Text: the text to be displayed, which can be formatted.

Duration: the time when the message is displayed. Length_short or length_long

Public void setduration (INT duration)

Set the display time of the toast window.

Public void setgravity (INT gravity, int xoffset, int yoffset)

Set the display position of the toast window on the screen.

Public void setmargin (float horizontalmargin, int verticalmargin)

Set the margins of the toast window.

Parameters:

Horizontalmargin: horizontal margin that defines the left and right boundary of the container and the distance between the notification window with the percentage of its container width.

Verticalmargin: vertical margin that defines the distance between the upper and lower boundary of the container and the notification window with the percentage of its container height.

Public void settext (INT resid)

Use string resources to update text in the toast window.

Parameters:

Resid: new text to be used in the toast window.

Public void settext (charsequence S)

Use the text in the parameter to update the text in the toast window.

Parameters:

S: new text to be used in the toast window.

Public void show ()

Display the toast window.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.