"Go" "java/android" toast use method Daquan

Source: Internet
Author: User

A Toast is a view that quickly displays a small amount of information to the user. A Toast floats on the application to display information to the user, it never gets the focus, does not affect the user's input, and so on, mainly for some help/hints.
The most common way to create a Toast is to use a static method Toast.maketext
I'm using SDK 2.2.

1. Default display mode

Java code

2. Customizing the display location

Java code

3. With the picture

Java code

1 Toast Toast=toast.maketext (Getapplicationcontext (), "show Toast with pictures", +);  2 toast.setgravity (gravity.center, 0, 0);  3//Create Picture View object  4 ImageView imageview= new ImageView (Getapplicationcontext ());  5//Set Picture  6 Imageview.setimageresource (r.drawable.ic_launcher);  7//Get the toast Layout  8 linearlayout Toastview = (linearlayout) Toast.getview ();  

4. Fully customizable display mode


Java code

1//inflater means inflatable  2//layoutinflater This class is used to instantiate the layout of an XML file to its corresponding View object  3 Layoutinflater inflater = Getlayoutinflater ( );  4//Fill in a View object by developing an XML file and layout ID  5 View layout = Inflater.inflate (R.layout.custom2, (ViewGroup) Findviewbyid ( R.id.lltoast));  6  7 ImageView image = (ImageView) Layout.findviewbyid (r.id.tvimagetoast);  8//Set picture in Picture view in layout  

5. Calls from other threads through Handler

Java code

1//Call Method 1  2//thread th=new Thread (this);  3//th.start ();  4//Call Method 2  5 handler.post (New Runnable () {  6 @Override  7 public void Run () {  8 showtoast ();  

Java code

Java code

1 Handler handler=new Handler () {  2 @Override  3 public void Handlemessage (Message msg) {  4 int What=msg.wha t;  5 switch (what) {  6 Case 1:  7 showtoast ();  8 break;  

Java code

1 @Override 2 public void Run () {3 handler.sendemptymessage (1); 4}

Original address: http://daikainan.iteye.com/blog/1405575

"Go" "java/android" toast use method Daquan

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.