Basic usage of Android active components

Source: Internet
Author: User

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

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.