Android Learning: OnClick +findviewbyid+toast Basics

Source: Internet
Author: User

One: Source code







Second: Knowledge points
1: Custom button time toast
(1) In Activity_main.xml, add the Click event to the control button
android:onclick= "Test"
Where test is a custom function name
(2) Declaring the test function in Mainactivity.java
(3) Add Toast message reminder in test function
Toast toast = Toast.maketext (Mainactivity.this, "clicked Button", Toast.length_short);
The screen is centered and the x-axis and y-axis offsets are 0
Toast.setgravity (gravity.center, 0, 0);
Toast.show ();


2:findviewbyid
Gets the element, through the R class
R.id.textview1
R.string.textchange



3: Custom String element
In the Res/values/strings.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "Buttonmsg" >clickMe</string>
</resources>



4: Internationalization
Create a directory below res VALUES-ZH-RCN
Create Strings.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "Buttonmsg" > Click me </string>
</resources>

Android Learning: OnClick +findviewbyid+toast Basics

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.