use in an activity Toast
toasts are a great way to alert your Android system, and you can use it to communicate short messages to users in a program that automatically disappears after a period of time and does not occupy any screen space.
Steps to use:
1. First you need to define a popup toast trigger point, there is a button on the interface, we have to click on this button to pop up a toast.
protected void OnCreate (Bundle savedinsta Ncestate) {
Super.oncreate (savedinstancestate);
Requestwindowfeature (Window.feature_no_title);
Setcontentview (r.layout.first_layout);
Button button1 = (button) Findviewbyid (r.id.button_1);
/* Use the Findviewbyid () method to get to the element defined in the layout file, where we pass in r.id.button_1 to get an instance of the button,
The FINDVI activity itself is a context object the Ewbyid () method returns a View object, which we need to transform downward to turn it into a Button object. */
Button1.setonclicklistener (New Onclicklistener () {
//We register a listener for the button by calling the Setonclicklistener () method.
@Override
public void OnClick (View v) {
//toast, a Toast object is created by a static method Maketext () and then called Show () to display the toast.
Toast.maketext (Firstactivity.this, "You clicked Button 1",
Toast.length_short). Show ();
/* Maketext (context[activity itself is a context object],toast the text displayed in
Capacity Toast.length_short| | Toast.length_long* *
}
});
}
(Android first line code) Toast