In the busy two days of Android learning process finally got some of their own satisfied with the harvest.
The first is to build Android project and then do some button and toast with a lot of work still to be done.
Let me begin by saying the steps that need to be done:
First you need to create a layout in the res file that belongs to your current activity (XML), code-ing, then load your layout in the Java file under your package file, and if you want to make a toast then look at the next code OK, The following code is a manual revision of the revision, there may be errors, please forgive me.
First, the start is to do the button.
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Wrap_content"4 Android:layout_height= "Wrap_content"5 android:orientation= "vertical" >6 7 <Button8 Android:id= "@+id/button"9 Adnroid:layout_width= "Match_parent"Ten Android:layout_height= "Match_parent" One Android:text= "button"text displayed on the//button A android:textsize= "20px"//Control text size - /> - the </LinearLayout>
After you have finished making the button, you should load your button into your layout and make a toast appear;
See this long package name, I said it was played for a long time to find out
Packagecom.example.***;//* * * is the name of your projectImportandroid.app.Activity;ImportAndroid.os.Bundle;ImportAdnroid.widget.Button;ImportAndroid.widget.Toast;ImportAndroid.view.Window;ImportAndroid.view.View.onClickListener;ImportAndroid.view.View; Public classMyActivityextendsactivity{@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //requestwindowfeature (Window.feature_no_title); //Show feature misspelled many times, check for a long time error, the role is to remove the title barSetcontentview (r.layout.firstlayout); Button Toast=(Button) Findviewbyid (R.id.button); Toast.setonclicklistener (NewOnclicklistener () {///This side needs to load a Android.view.View.OnClickListener package, @Override Public voidoncreat (View v) {//view requires Android.view.View package to be able to use Toast.maketext (myactivity. This, "Toast", Toast.length_short). Show (); //}});}
Android 04.16