Android message prompt

Source: Internet
Author: User

In Android, ifProgramWhen you do not need to perform any operations, you can use the lightweight message toast provided by Android.

Text prompt.

 With ImageMessage prompt

 

Use A toast instance.
Public Class Toasttest Extends Activity
{
@ Override
Public Void Oncreate (bundle savedinstancestate)
{
Super . Oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Button simple = (button) findviewbyid (R. Id. Simple );
// Bind the event listener to the Click Event of the button
Simple. setonclicklistener ( New Onclicklistener ()
{
@ Override
Public Void Onclick (View Source)
{
// Create a toast prompt
Toast = toast. maketext (toasttest. This
, "Simple prompt information"
// Set the toast prompt duration
, Toast. length_short );
Toast. Show ();
}
});
Button bn = (button) findviewbyid (R. Id. bn );
// Bind the event listener to the Click Event of the button
BN. setonclicklistener ( New Onclicklistener ()
{
@ Override
Public Void Onclick (View Source)
{
// Create a toast prompt
Toast = toast. maketext (toasttest. This
, "Prompts with images"
// Set the toast prompt duration
, Toast. length_long );
Toast. setgravity (gravity. Center, 0, 0 );
// Get the original view in the toast prompt
View toastview = toast. getview ();
// Create an imageview
Imageview image = New Imageview (toasttest. This );
Image. setimageresource (R. drawable. tools );
// Create a linearlayout container
Linearlayout LL = New Linearlayout (toasttest. This );
// Add images and original views to linearlayout
Ll. addview (image );
Ll. addview (toastview );
Toast. setview (LL );
Toast. Show ();
}
});
}
}

URL:Http://greatverve.cnblogs.com/archive/2012/01/10/android-toast.html

 

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.