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