Getting Started with Android

1. Environment preparation for Android development;

1.  Install JDK;

2.  Install Eclipse ;

3.  Install the SDK ;

The first is to configure the environment variables, the specific way to visit: https://jingyan.baidu.com/article/f71d603757965b1ab641d12a.html

4.  Install the Android development plug- in on Eclipse ;

This is an ADT package. I used ADT22.3.0 at the beginning, but after installing it, there were problems such as conflict with the SDK version, and I couldn't create an Android application project . The solution is to replace the version after ATD23.0.0 , the problem can be solved.

5.  Configure the Android development environment of Eclipse ;
 
an executable file.

This program can download and update different Android systems. At the beginning, I downloaded Android 8.0 , which was not supported by Eclipse at that time , and the .xml document of its page layout could not be displayed in eclipse at all. After that, the solution is to download a lower version of Android . I downloaded Android4.4.2 , so that's it.

To run the Android project on the computer, you must use the AVD manger , which is an executable file in the same directory as the SDK manger .

This is a program used to create a virtual machine, through which a virtual machine of the Android system can be run on the computer, but this program must have the accelerator program Haxm , and it must be version 6.0 and later. Some computers already have an error message when the virtual machine is turned on. If there is none, you need to download a copy from the official website and install it directly to solve the problem. The download address is: https://software.intel.com/zh-cn/android/articles/intel-hardware-accelerated-execution-manager

2. An important part of Android development;

1. Activity

This is the part used to process page data and inherits the Activity class. Each Activity class is bound to an XML document in a Layout , which is the page layout displayed on the Android phone. These classes are placed in the src folder.

2. Layout

All APP page files placed in this folder are in .xml format. When creating the activity , Eclipse will automatically create a .xml file and place it in the layout folder;

3. AndroidManifest.xml;

This is the file used to store registered activities . All Activity classes must be registered in this file in order to be used normally. The registration format is as follows:

Three, Android program example;

1.  Activity class;

 

package com.example.study;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate (savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	public void submit(View view)
	{
		EditText name=(EditText)this.findViewById(R.id.name);
		EditText pass=(EditText)this.findViewById(R.id.password);
		String user=name.getText().toString().trim();
		String password=pass.getText().toString().trim();
		if(user.equals("chen")&&password.equals("123456"))
		{
			Intent intent=new Intent();  
            intent.setClass(MainActivity.this,Home.class);  
            MainActivity.this.startActivity(intent);
		}
		else
		{
			Toast toast=Toast.makeText(this, user+"Username does not exist or password is incorrect"+password, 5);
			toast.show();
		}
		
	}
}

 

package com.example.study;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class Home extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate (savedInstanceState);
		setContentView(R.layout.activity_home);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.home, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}

 

2.  Layout layout file;

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    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.example.study.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Enter account password:"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="30dp"
        android:text="姓名:"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <EditText
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/textView2"
        android:inputType="textPersonName" >

    </EditText>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/name"
        android:layout_marginTop="30dp"
        android:text="password"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <EditText
        android:id="@+id/password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/name"
        android:layout_alignRight="@+id/name"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:onClick="submit"
        android:text="login" />

</RelativeLayout>

 

<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.example.study.Home" >

    <TextView
 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Welcome To Our World" />

</RelativeLayout>

 

3.  Effect display;

When the login password is wrong, the system prompts an error message;

When the account passwords are all correctly matched, the interface jumps to another interface.
 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326270639&siteId=291194637