Basic usage of activities;
Register the activity in the Androidmanifest.xml file.
Hide title bar
To create a menu in an activity using menu
Destroy an activity
Package Com.example.activitytest;import Android.app.activity;import Android.os.bundle;import android.view.Menu; Import Android.view.menuitem;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.window;import Android.widget.button;import Android.widget.toast;public class FirstActivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Requestwindowfeature (window.feature_no_title);//Hide title bar Setcontentview (R.layout.first_layout );//Load layout Button button1 = (button) Findviewbyid (r.id.button_1); Button1.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View v) {//TODO auto-generated method Stub//toast.maketext (Firstactivity.this, "you clicked Button 1 ", Toast.length_short). Show (), Finish ();//Destroy an activity, finish and press the back key effect});} @Overridepublic boolean oncreateoptionsmenu (Menu menua) {//TODO auto-generated Method Stubgetmenuinflater (). Inflate ( R.menu.main, MenUA)///menu will not be displayed by default, only by pressing the menu key, the menus will be displayed at the bottom. return true;} @Overridepublic boolean onoptionsitemselected (MenuItem Item) {//TODO auto-generated method Stubswitch (Item.getitemid ( ) {Case R.id.add_item:toast.maketext (this, "clicked Add", Toast.length_long). Show (); Break;case R.id.remove_item: Toast.maketext (This, "You clicked Remove_item", Toast.length_short). Show (); break;default:break;} return super.onoptionsitemselected (item);}}
<manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "Com.example.activitytest" android:versioncode= "1" android:versionname= "1.0" > <uses-sdk android:minsdkversion= "14" android:targetsdkversion= "/> <application android:allowbackup=" true " android:icon=" @ Drawable/ic_launcher " android:label=" @string/app_name " android:theme=" @style/apptheme "> < Activity android:name= "com.example.activitytest.FirstActivity" android:label= "This is FirstActivity01" > <intent-filter> <action android:name= "Android.intent.action.MAIN"/> < Category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity > </application></manifest>
<?xml version= "1.0" encoding= "Utf-8"? ><menu xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:id= "@+id/add_item" android:title= "add"/> <item android:id= "@+ Id/remove_item " android:title=" Remove "/></menu>
Basic usage of Android active components