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