in the system, the user's actions can be prompted through a dialog, but there is another set of more friendly hints on the Android platform, and this interface will not interrupt the user's normal operation when prompting the user, this dialog can be implemented by the toast component. A toast is a component that takes a simple cue message as the primary display operation, and the inheritance structure of Android.widget.Toast in Android is as follows:Java.lang.Object ? android.widget.Toast Common methods:
No. |
Methods and Constants |
Type |
Describe |
1 |
public static final int Length_long |
Constant |
Long display time |
2 |
public static final int Length_short |
Constant |
Short display time |
3 |
Public Toast (Context context) |
Ordinary |
To create a Toast object |
4 |
public static Toast Maketext (context context, int resId, int duration) |
Ordinary |
Creates a Toast object and specifies the ID of the display text resource, and the time the information is displayed |
5 |
public static Toast Maketext (context context, charsequence text, int duration) |
Ordinary |
Creates a Toast object and specifies that the display text resource, and the display time of the information |
6 |
public void Show () |
Ordinary |
Display information |
7 |
public void setduration (int duration) |
Ordinary |
Set the displayed time |
8 |
public void Setview (view view) |
Ordinary |
Set the view component to be displayed |
9 |
public void SetText (int resId) |
Ordinary |
Set the displayed text resource ID |
10 |
public void SetText (Charsequence s) |
Ordinary |
Set the text to display directly |
11 |
public void setgravity (int gravity, int xoffset, int yoffset) |
Ordinary |
To set the alignment of a component |
12 |
Public View GetView () |
Ordinary |
Get the internal included view component |
13 |
public int Getxoffset () |
Ordinary |
Returns the x-coordinate position of the component |
14 |
public int Getyoffset () |
Ordinary |
Returns the y-coordinate position of the component |
15 |
public void Cancel () |
Ordinary |
Cancel Display |
XML file Configuration
<span style= "FONT-SIZE:14PX;" ><?xml version= "1.0" encoding= "UTF-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/ Res/android " android:id=" @+id/toast_layout_root " android:layout_width=" fill_parent " android:layout _height= "Fill_parent" android:background= "#DAAA" android:orientation= "Horizontal" android:padding= "10DP" > <imageview android:id= "@+id/image" android:layout_width= "Wrap_content" android: layout_height= "Fill_parent" android:layout_marginright= "10DP" android:src= "@drawable/kill" / > <textview android:id= "@+id/text" android:layout_width= "Wrap_content" android: layout_height= "Fill_parent" android:text= "Custom Hints" /></linearlayout></span>
Java file Configuration
<span style= "FONT-SIZE:14PX;" >package com.example.toast;import android.app.activity;import Android.os.bundle;import android.view.Gravity; Import Android.view.layoutinflater;import Android.view.view;import Android.widget.button;import Android.widget.toast;public class Mainactivity extends Activity {private Button button1, Button2; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main); button1 = (Button) This.findviewbyid (r.id.button1); button2 = (Button) This.findviewbyid (R.id.button2); Button1.setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method stub//original Hint Toast.maketext (mainactivity.this, "Custom Prompt Box", Toast.length_short). Show ();}); /For button Set Click event Button2.setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO Auto-generated method Stubview view = Layoutinflater.from (Mainactivity.this). Inflate (r.layout. LinearLayout, null);//Convert layout layout to view object toast toast = new Toast (mainactivity.this);//create Toast Prompt toast.setgravity ( Gravity.center, 0, 0);//Set the location of the toast hint toast.setview (view);//Add the layout to the Toast Component toast.show ();//Show Prompt});}} </span>
Original hint effect:
Custom Toast Display
Toast component is relatively simple mainly in order to user's operation friendly hints, in the development of more commonly used to, I hope you must master
Next Forecast: ListView Data List Display component