(Android first line code) Toast

Source: Internet
Author: User

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

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.