Android Quick Start (ii) Android development environment build and Hello World

Source: Internet
Author: User

Basic understanding of the Java syntax, next, we open together the Mystery of Hello World tour.


(i) Android development environment construction

It was a very laborious task to build an Android development environment before, download Eclipse, install ADT and so on, and now the Android official gives us a full set of configurations.

Https://developer.android.com/sdk/index.html

Remember to install the JDK before you build your Android development environment


(ii) Start the Hello World tour

(1) Create a Hello World project

Install eclipse with ADT, open Eclipse, create a new project

All the way next and finish down, the final build project is as follows

Different versions of the project created, the generated content will be different, I use the 4.4 version of the SDK

Run the project


(2) Project structure analysis

Build project structure is more complex, want to learn more about the students can continue to see, can also be temporarily skipped.

1.drawable Directory exists picture

Android support different resolution phone picture adaptation, the corresponding picture in the corresponding folder, the picture is generally placed in the drawable-hdpi, the image of the XML in the drawable

2.layout Directory exists layout

The layout is the UI that is displayed, also supports different resolutions and the screen is specially adapted

3.values Directory has numeric resource information

color values, string corresponding to the size of the dimens, styles corresponding to the theme style, menu information, etc.

4.androidmanifest.xml file

Declare activity, Service, broadcast and other information, set permissions, package name, version information, etc. that the app can use

5.gen folder

Save the auto-generated R.java file located under the Android Project package, and the R file holds the resource information map value, which is called directly in the program.

6.libs folder

Lib that holds third-party calls


(3) Hello wolrd in depth

To use the control, you need to get the control, take control through the control ID value in R

Add the ID value of HelloWorld text in Fragment_main.xml

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:paddingbottom= "@dimen/activity_vertical_margin"    android:paddingleft= "@dimen/activity_ Horizontal_margin "    android:paddingright=" @dimen/activity_horizontal_margin "    android:paddingtop=" @dimen /activity_vertical_margin "    tools:context=" Com.peter.demo.helloworld.mainactivity$placeholderfragment ">    <textview        android:id= "@+id/hello_world"        android:layout_width= "Wrap_content"        android: layout_height= "Wrap_content"        android:text= "@string/hello_world"/></relativelayout>


Get the TextView object, display it to the assigned value

In the Mainactivity.java
/**     * A placeholder fragment containing a simple view.     *    /public static class Placeholderfragment        extends Fragment {public        placeholderfragment () {        }        @ Override public        View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {            View Rootview = inflater.inflate (R.layout.fragment_main, container, false);            TextView TV = (TextView) Rootview.findviewbyid (R.id.hello_world);            Tv.settext ("Hello world!");            return rootview;        }    }

(4) HelloWorld extension

Complete the HelloWorld, let us continue to play together, the ever-changing HelloWorld.


1. Object-oriented HelloWorld

Create a HelloWorld object

/** * HelloWorld Object *  * @author Peter_wang * @create-time 2014-5-11 a.m. 10:37:04 */public class HelloWorld {    private String MText;    Public HelloWorld () {        this.mtext = "Hello world!";    }    Public String Getmtext () {        return mText;    }    public void Setmtext (String mText) {        this.mtext = MText;    }}

Modify the TextView section in Mainactivity.java

TextView TV = (TextView) Rootview.findviewbyid (R.id.hello_world); HelloWorld HelloWorld = new HelloWorld (); Tv.settext (Helloworld.getmtext ());


2. Modify the HelloWorld display style

TextView TV = (TextView) Rootview.findviewbyid (R.id.hello_world); Tv.settext ("Hello world!"); /Set the display color to green tv.settextcolor (color.green);//Set the font size tv.settextsize (18);//Bold Textpaint paint =  tv.getpaint ();  








(iii) Summary of studies

Development environment is easy to build, HelloWorld create projects automatically generated, familiar with the structure of the whole project, interested students to play their own creative change code, write code must enjoy, all in their own grasp, to create their own small things.


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.