The first simple Android project

Source: Internet
Author: User

Development platform: Windows7+eclipse+andriod SDK (24.0) +adt (23.0.4). The setup of this environment has been described in the previous article (Appium test under Mobile testing).

Specific steps:

1, build an Android project, fill in the project name, and then select the Minimum requeired SDK: If you select this SDK version is less than 3.0 then creating an installation project will also create a APPCOMAT_V7 project, This is primarily intended to be compatible with low-version Android systems; If you don't want this v7 project, choose Minimum requeired SDK is more than 3.0, here I choose API19 (Android 4.4), compiled version is also this. Then click on the next step, of course, in the Launcher icon and Activity page can be configured to configure their own icon and activity.

2, after the project is built, there are 3 XML needs to be modified: Androidmanifest.xml,res/layout/main.xml and Res/values/strings.xml. The distribution of their effects is:

Androidmanifest:

Main:app main form layout file, what your app looks like here, with design and text two modes

Strings: Can be understood as a i18n file, this file is used to store the various string of program calls

Main.xml:

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent">    <TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "180DP"Android:text= "@string/default_message"Android:id= "@+id/hellotextview"Android:textcolor= "#00ff00"android:gravity= "Center"/>    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/button_send"Android:id= "@+id/hellobutton"android:layout_gravity= "Center"/></LinearLayout>

STRINGS.XMLS:

<Resources>    <stringname= "App_name">MyAndroid3</string>    <stringname= "Button_send">Say something</string>    <stringname= "Default_message">Click Button below!</string>    <stringname= "Interact_message">You just clicked on the button!</string></Resources>

3, then create a new class, here I am myactivity, and then add the following code:

 Public classMyActivityextendsactivity{/*** Called when the activity is first created. */     Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);      Setcontentview (R.layout.main); Define HELLTOBTN Button hellobtn=(Button) Findviewbyid (R.id.hellobutton); Monitor Hellobtn Hellobtn.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {//definition Hellotextview TextView Hellotv=(TextView) Findviewbyid (R.id.hellotextview); //Popup Toast Floating control display btn is clickedToast.maketext (myactivity. This, "Clicked", Toast.length_short). Show (); //Display the contents of Interact_message on TextViewHellotv.settext (r.string.interact_message);    }        }); }}

3, after compiling the correct, you can connect to the real machine (need to open the Developer Debug mode) or simulator, select this project and run as Android application, then you can see the APK is installed, open apk start Rock Bar.

The first simple Android project

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.