public class
Toast
extends Object
java.lang.Object
↳ android.widget.Toast
Class Overview
A toast is a view containing a quick little message for the user. The toast class helps you create and show those.
When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved.
The easiest way to use this class is to call one of the static methods that constructs everything you need and returns a new Toast object.
Developer Guides
For information about creating Toast notifications, read the Toast Notifications developer guide.
Summary
Constants
int LENGTH_LONG Show the view or text notification for a long period of time.
int LENGTH_SHORT Show the view or text notification for a short period of time.
Public Constructors
Toast(Context context)
Construct an empty Toast object.
Public Methods
void cancel()
Close the view if it's showing, or don't show it if it isn't showing yet.
int getDuration()
Return the duration.
int getGravity()
Get the location at which the notification should appear on the screen.
float getHorizontalMargin()
Return the horizontal margin.
float getVerticalMargin()
Return the vertical margin.
View getView()
Return the view.
int getXOffset()
Return the X offset in pixels to apply to the gravity's location.
int getYOffset()
Return the Y offset in pixels to apply to the gravity's location.
static Toast makeText(Context context, int resId, int duration)
Make a standard toast that just contains a text view with the text from a resource.
static Toast makeText(Context context, CharSequence text, int duration)
Make a standard toast that just contains a text view.
void setDuration(int duration)
Set how long to show the view for.
void setGravity(int gravity, int xOffset, int yOffset)
Set the location at which the notification should appear on the screen.
void setMargin(float horizontalMargin, float verticalMargin)
Set the margins of the view.
void setText(int resId)
Update the text in a Toast that was previously created using one of the makeText() methods.
void setText(CharSequence s)
Update the text in a Toast that was previously created using one of the makeText() methods.
void setView(View view)
Set the view to show.
void show()
Show the view for the specified duration.
[Expand]
Inherited Methods
From class java.lang.Object
Constants
public static final int LENGTH_LONG
Added in API level 1
Show the view or text notification for a long period of time. This time could be user-definable.
See Also
setDuration(int)
Constant Value: 1 (0x00000001)
public static final int LENGTH_SHORT
Added in API level 1
Show the view or text notification for a short period of time. This time could be user-definable. This is the default.
See Also
setDuration(int)
Constant Value: 0 (0x00000000)
Public Constructors
public Toast (Context context)
Added in API level 1
Construct an empty Toast object. You must call setView(View) before you can call show().
Parameters
context The context to use. Usually your Application or Activity object.
Public Methods
public void cancel ()
Added in API level 1
Close the view if it's showing, or don't show it if it isn't showing yet. You do not normally have to call this. Normally view will disappear on its own after the appropriate duration.
public int getDuration ()
Added in API level 1
Return the duration.
See Also
setDuration(int)
public int getGravity ()
Added in API level 1
Get the location at which the notification should appear on the screen.
See Also
Gravity
getGravity()
public float getHorizontalMargin ()
Added in API level 1
Return the horizontal margin.
public float getVerticalMargin ()
Added in API level 1
Return the vertical margin.
public View getView ()
Added in API level 1
Return the view.
See Also
setView(View)
public int getXOffset ()
Added in API level 1
Return the X offset in pixels to apply to the gravity's location.
public int getYOffset ()
Added in API level 1
Return the Y offset in pixels to apply to the gravity's location.
public static Toast makeText (Context context, int resId, int duration)
Added in API level 1
Make a standard toast that just contains a text view with the text from a resource.
Parameters
context The context to use. Usually your Application or Activity object.
resId The resource id of the string resource to use. Can be formatted text.
duration How long to display the message. Either LENGTH_SHORT or LENGTH_LONG
Throws
if the resource can't be found.
Resources.NotFoundException
public static Toast makeText (Context context, CharSequence text, int duration)
Added in API level 1
Make a standard toast that just contains a text view.
Parameters
context The context to use. Usually your Application or Activity object.
text The text to show. Can be formatted text.
duration How long to display the message. Either LENGTH_SHORT or LENGTH_LONG
public void setDuration (int duration)
Added in API level 1
Set how long to show the view for.
See Also
LENGTH_SHORT
LENGTH_LONG
public void setGravity (int gravity, int xOffset, int yOffset)
Added in API level 1
Set the location at which the notification should appear on the screen.
See Also
Gravity
getGravity()
public void setMargin (float horizontalMargin, float verticalMargin)
Added in API level 1
Set the margins of the view.
Parameters
horizontalMargin The horizontal margin, in percentage of the container width, between the container's edges and the notification
verticalMargin The vertical margin, in percentage of the container height, between the container's edges and the notification
public void setText (int resId)
Added in API level 1
Update the text in a Toast that was previously created using one of the makeText() methods.
Parameters
resId The new text for the Toast.
public void setText (CharSequence s)
Added in API level 1
Update the text in a Toast that was previously created using one of the makeText() methods.
Parameters
s The new text for the Toast.
public void setView (View view)
Added in API level 1
Set the view to show.
See Also
getView()
public void show ()
Added in API level 1
Show the view for the specified duration.
คลาสาธารณะ
ขนมปังปิ้ง
ขยาย Object
java.lang.Object
↳ android.widget.Toast
Class ภาพรวม
ขนมปังมีมุมมองประกอบด้วยข้อความเล็กน้อยอย่างรวดเร็วสำหรับผู้ใช้ ชั้นขนมปังช่วยคุณสร้าง และแสดงผู้
เมื่อมุมมองจะแสดงผู้ใช้ ปรากฏเป็นมุมลอยผ่านแอพลิเคชัน มันจะไม่ได้รับความ ผู้ใช้คงจะกลางพิมพ์อย่างอื่น ความคิดจะถูกสิ่งรอบข้างเป็นที่สุด ในขณะที่ยังคง แสดงผู้ใช้ข้อมูลที่คุณต้องการให้ดู ตัวอย่างคือ ตัวควบคุมระดับเสียง และข้อความสั้น ๆ ที่บอกว่า ที่ตั้งค่าของคุณได้ด้วย
วิธีง่ายที่สุดใช้คลาสนี้จะเรียกวิธีการแบบคงที่สร้างทุกสิ่งที่คุณต้องการ และกลับเป็นใหม่ปังวัตถุอย่างใดอย่างหนึ่ง
แนะนำนักพัฒนา
สำหรับข้อมูลเกี่ยวกับการสร้างการแจ้งเตือน ขนมปังอ่านการแจ้งเตือนขนมปังพัฒนาคู่มือการ
สรุป
คง
int LENGTH_LONG แสดงมุมมองหรือข้อความแจ้งเตือนเป็นระยะเวลานานของเวลา
int LENGTH_SHORT แสดงมุมมองหรือข้อความแจ้งเตือนเป็นระยะเวลาสั้น ๆ ของเวลา
ตัวสร้างสาธารณะ
ขนมปัง (บริบทบริบท)
สร้างการว่างเปล่าขนมปังวัตถุ
วิธีการสาธารณะ
ยกเลิก cancel()
ปิดมุมมองจะแสดง หรือไม่ก็ถ้ามันไม่แสดงยัง
int () getDuration
ระยะเวลาได้
int () getGravity
รับสถานที่ที่ปรากฏการแจ้งเตือนบนหน้าจอ
ลอย(getHorizontalMargin)
แนวขอบได้
ลอย(getVerticalMargin)
แนวขอบได้
ดู(getView)
กลับดู
int getXOffset()
กลับตรงข้าม X เซลการใช้สถานของแรงโน้มถ่วง
int () getYOffset
กลับตรงข้าม Y เซลการใช้สถานของแรงโน้มถ่วง
makeText ขนมปังคง (บริบทบริบท จุด int, int ระยะเวลา)
ทำขนมปังแบบมาตรฐานที่ประกอบด้วยมุมมองข้อความกับข้อความจากทรัพยากรเพียง
makeText ขนมปังคง (บริบทบริบท CharSequence ข้อความ ระยะเวลา int)
ทำขนมปังแบบมาตรฐานที่ประกอบด้วยเพียงมุมมองข้อความ
โมฆะ setDuration (int ช่วง)
ชุดระยะการแสดงกันดู
โมฆะ setGravity (แรงโน้มถ่วง int, int xOffset, int yOffset)
ตั้งค่าตำแหน่งที่ปรากฏการแจ้งเตือนบนหน้าจอ
setMargin เป็นโมฆะ (horizontalMargin ลอย ลอย verticalMargin)
ตั้งค่าระยะขอบของมุมมอง
โมฆะ setText (int จุด)
อัพเดตข้อความในขนมปังที่ก่อนหน้านี้หนึ่งของ makeText() วิธี
โมฆะ setText (CharSequence s)
อัพเดตข้อความในขนมปังที่ก่อนหน้านี้หนึ่งของ makeText() วิธี
โมฆะ setView (วิว)
ตั้งมุมมองเพื่อแสดง
()ดูโมฆะ
ดูสำหรับการระบุระยะเวลาการ
[ขยาย]
วิธีสืบทอด
จากคลาส java.lang.Object
Constants
สุดท้าย int สาธารณะคง LENGTH_LONG
เพิ่มใน API ระดับ 1
แสดงมุมมองหรือข้อความแจ้งเตือนสำหรับรอบระยะเวลายาวนาน เวลานี้อาจเป็นผู้ใช้เองได้
ยัง
setDuration (int)
ค่าคง: 1 (0x00000001)
สุดท้าย int สาธารณะคง LENGTH_SHORT
เพิ่มใน API ระดับ 1
แสดงมุมมองหรือข้อความแจ้งเตือนในระยะเวลาสั้น ๆ ได้ เวลานี้อาจเป็นผู้ใช้เอง ต้น
ดู
setDuration (int)
ค่าคง: 0 (0x00000000)
ตัวสร้างสาธารณะ
ขนมปังสาธารณะ (บริบทบริบท)
เพิ่มใน API ระดับ 1
สร้างวัตถุขนมปังเปล่า คุณต้องโทร setView(View) ก่อนที่คุณสามารถเรียกดู().
พารามิเตอร์
บริบทบริบทการใช้งาน ปกติของโปรแกรมประยุกต์หรือกิจกรรมวัตถุ
วิธีการสาธารณะ
()ยกเลิกเป็นโมฆะสาธารณะ
เพิ่มใน API ระดับ 1
ปิดมุมมองจะแสดง หรือไม่แสดงถ้ามันไม่แสดงได้ ไม่ปกติได้เรียกนี้ ปกติดูจะหายไปในช่วงเวลาของตัวเองหลังจากงาน
int สาธารณะ getDuration ()
เพิ่มใน API ระดับ 1
ระยะเวลาได้
ยัง
setDuration (int)
int สาธารณะ getGravity ()
เพิ่มใน API ระดับ 1
รับสถานที่ที่ปรากฏการแจ้งเตือนบนหน้าจอ
ยัง
แรงโน้มถ่วง
(getGravity)
ลอยสาธารณะ getHorizontalMargin ()
เพิ่มใน API ระดับ 1
แนวขอบได้
ลอยสาธารณะ getVerticalMargin ()
เพิ่มใน API ระดับ 1
แนวขอบได้
() getView มุมมองสาธารณะ
เพิ่มใน API ระดับ 1
กลับดู
ยัง
setView (ดู)
int สาธารณะ getXOffset ()
เพิ่มใน API ระดับ 1
กลับ X ตรงข้ามเซลการใช้สถานของแรงโน้มถ่วง
int สาธารณะ getYOffset ()
เพิ่มใน API ระดับ 1
กลับตรงข้าม Y เซลการใช้สถานของแรงโน้มถ่วง
สาธารณะคงขนมปัง makeText (บริบทบริบท จุด int, int ระยะเวลา)
เพิ่มใน API ระดับ 1
ทำขนมปังแบบมาตรฐานที่ประกอบด้วยเพียงมุมมองข้อความกับข้อความจากทรัพยากร
พารามิเตอร์
บริบทบริบทการใช้ ปกติของโปรแกรมประยุกต์หรือกิจกรรมวัตถุ
รหัสทรัพยากรของทรัพยากรสายอักขระจะใช้จุด ได้จัดรูปแบบข้อความ
ระยะเวลาว่านานก่อนที่จะแสดงข้อความได้ LENGTH_SHORT หรือ LENGTH_LONG
พ่น
ถ้าไม่พบทรัพยากร.
Resources.NotFoundException
สาธารณะคงขนมปัง makeText (บริบทบริบท CharSequence ข้อความ ระยะเวลา int)
เพิ่มใน API ระดับ 1
ทำขนมปังแบบมาตรฐานที่ประกอบด้วยเพียงมุมมองข้อความ
พารามิเตอร์
บริบทบริบทการใช้ ปกติของโปรแกรมประยุกต์หรือกิจกรรมวัตถุ
ข้อความข้อความจะแสดงขึ้น ได้จัดรูปแบบข้อความ
ระยะเวลาว่านานก่อนที่จะแสดงข้อความได้ LENGTH_SHORT หรือ LENGTH_LONG
setDuration โมฆะสาธารณะ (ระยะเวลา int)
เพิ่มใน API ระดับ 1
ชุดระยะการแสดงกันดู
ยัง
LENGTH_SHORT
LENGTH_LONG
สาธารณะโมฆะ setGravity (แรงโน้มถ่วง int, int xOffset, int yOffset)
เพิ่มใน API ระดับ 1
ตั้งค่าตำแหน่งที่ปรากฏการแจ้งเตือนบนหน้าจอ
ยัง
แรงโน้มถ่วง
() getGravity
setMargin โมฆะสาธารณะ (horizontalMargin ลอย ลอย verticalMargin)
เพิ่มใน API ระดับ 1
ตั้งค่าระยะขอบของมุมมอง
พารามิเตอร์
horizontalMargin ขอบแนวนอน เปอร์เซ็นต์ของความกว้างคอนเทนเนอร์ ระหว่างขอบของภาชนะและการแจ้งเตือน
verticalMargin ขอบแนวตั้ง ในเปอร์เซ็นต์ของความสูงภาชนะ ระหว่างขอบของภาชนะและการแจ้งเตือน
setText โมฆะสาธารณะ (จุด int)
เพิ่มใน API ระดับ 1
อัพเดตข้อความในขนมปังที่ก่อนหน้านี้หนึ่งของ makeText() วิธี
พารามิเตอร์
จุดข้อความใหม่สำหรับขนมปัง
setText โมฆะสาธารณะ (CharSequence s)
เพิ่มใน API ระดับ 1
อัพเดตข้อความในขนมปังที่ก่อนหน้านี้หนึ่งของ makeText() วิธี
พารามิเตอร์
s ข้อความใหม่สำหรับขนมปัง
สาธารณะโมฆะ setView (วิว)
เพิ่มใน API ระดับ 1
ตั้งมุมมองเพื่อแสดง
ยัง
(getView)
()ดูสาธารณะโมฆะ
เพิ่มใน API ระดับ 1
ดูสำหรับระยะเวลา
การแปล กรุณารอสักครู่..
![](//thimg.ilovetranslation.com/pic/loading_3.gif?v=b9814dd30c1d7c59_8619)
public class
Toast
extends Object
java.lang.Object
↳ android.widget.Toast
Class Overview
A toast is a view containing a quick little message for the user. The toast class helps you create and show those.
When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved.
The easiest way to use this class is to call one of the static methods that constructs everything you need and returns a new Toast object.
Developer Guides
For information about creating Toast notifications, read the Toast Notifications developer guide.
Summary
Constants
int LENGTH_LONG Show the view or text notification for a long period of time.
int LENGTH_SHORT Show the view or text notification for a short period of time.
Public Constructors
Toast(Context context)
Construct an empty Toast object.
Public Methods
void cancel()
Close the view if it's showing, or don't show it if it isn't showing yet.
int getDuration()
Return the duration.
int getGravity()
Get the location at which the notification should appear on the screen.
float getHorizontalMargin()
Return the horizontal margin.
float getVerticalMargin()
Return the vertical margin.
View getView()
Return the view.
int getXOffset()
Return the X offset in pixels to apply to the gravity's location.
int getYOffset()
Return the Y offset in pixels to apply to the gravity's location.
static Toast makeText(Context context, int resId, int duration)
Make a standard toast that just contains a text view with the text from a resource.
static Toast makeText(Context context, CharSequence text, int duration)
Make a standard toast that just contains a text view.
void setDuration(int duration)
Set how long to show the view for.
void setGravity(int gravity, int xOffset, int yOffset)
Set the location at which the notification should appear on the screen.
void setMargin(float horizontalMargin, float verticalMargin)
Set the margins of the view.
void setText(int resId)
Update the text in a Toast that was previously created using one of the makeText() methods.
void setText(CharSequence s)
Update the text in a Toast that was previously created using one of the makeText() methods.
void setView(View view)
Set the view to show.
void show()
Show the view for the specified duration.
[Expand]
Inherited Methods
From class java.lang.Object
Constants
public static final int LENGTH_LONG
Added in API level 1
Show the view or text notification for a long period of time. This time could be user-definable.
See Also
setDuration(int)
Constant Value: 1 (0x00000001)
public static final int LENGTH_SHORT
Added in API level 1
Show the view or text notification for a short period of time. This time could be user-definable. This is the default.
See Also
setDuration(int)
Constant Value: 0 (0x00000000)
Public Constructors
public Toast (Context context)
Added in API level 1
Construct an empty Toast object. You must call setView(View) before you can call show().
Parameters
context The context to use. Usually your Application or Activity object.
Public Methods
public void cancel ()
Added in API level 1
Close the view if it's showing, or don't show it if it isn't showing yet. You do not normally have to call this. Normally view will disappear on its own after the appropriate duration.
public int getDuration ()
Added in API level 1
Return the duration.
See Also
setDuration(int)
public int getGravity ()
Added in API level 1
Get the location at which the notification should appear on the screen.
See Also
Gravity
getGravity()
public float getHorizontalMargin ()
Added in API level 1
Return the horizontal margin.
public float getVerticalMargin ()
Added in API level 1
Return the vertical margin.
public View getView ()
Added in API level 1
Return the view.
See Also
setView(View)
public int getXOffset ()
Added in API level 1
Return the X offset in pixels to apply to the gravity's location.
public int getYOffset ()
Added in API level 1
Return the Y offset in pixels to apply to the gravity's location.
public static Toast makeText (Context context, int resId, int duration)
Added in API level 1
Make a standard toast that just contains a text view with the text from a resource.
Parameters
context The context to use. Usually your Application or Activity object.
resId The resource id of the string resource to use. Can be formatted text.
duration How long to display the message. Either LENGTH_SHORT or LENGTH_LONG
Throws
if the resource can't be found.
Resources.NotFoundException
public static Toast makeText (Context context, CharSequence text, int duration)
Added in API level 1
Make a standard toast that just contains a text view.
Parameters
context The context to use. Usually your Application or Activity object.
text The text to show. Can be formatted text.
duration How long to display the message. Either LENGTH_SHORT or LENGTH_LONG
public void setDuration (int duration)
Added in API level 1
Set how long to show the view for.
See Also
LENGTH_SHORT
LENGTH_LONG
public void setGravity (int gravity, int xOffset, int yOffset)
Added in API level 1
Set the location at which the notification should appear on the screen.
See Also
Gravity
getGravity()
public void setMargin (float horizontalMargin, float verticalMargin)
Added in API level 1
Set the margins of the view.
Parameters
horizontalMargin The horizontal margin, in percentage of the container width, between the container's edges and the notification
verticalMargin The vertical margin, in percentage of the container height, between the container's edges and the notification
public void setText (int resId)
Added in API level 1
Update the text in a Toast that was previously created using one of the makeText() methods.
Parameters
resId The new text for the Toast.
public void setText (CharSequence s)
Added in API level 1
Update the text in a Toast that was previously created using one of the makeText() methods.
Parameters
s The new text for the Toast.
public void setView (View view)
Added in API level 1
Set the view to show.
See Also
getView()
public void show ()
Added in API level 1
Show the view for the specified duration.
การแปล กรุณารอสักครู่..
![](//thimg.ilovetranslation.com/pic/loading_3.gif?v=b9814dd30c1d7c59_8619)