`

Android入门

 
阅读更多

一、Android开发之环境准备;

1. 安装JDK;

2. 安装Eclipse

3. 安装SDK

首先是配置环境变量,具体方式访问:https://jingyan.baidu.com/article/f71d603757965b1ab641d12a.html

4. Eclipse上安装Android开发插件;

这是一个ADT包,我一开始的时候用的是ADT22.3.0但是安装了之后出现与SDK版本冲突等问题,新建不了Android application project。解决方法就是换成ATD23.0.0之后的版本,问题就能解决。

5. 配置EclipseAndroid开发环境;
 
个可执行文件。

该程序可以下载更新不同的Android系统,一开始我下的是Android8.0,当时Eclipse并不支持,其页面布局的.xml文档在eclipse里完全显示不了。之后解决方法就是下载Android较低的版本,我下的就是Android4.4.2,这样就可以了。

要想在电脑上运行Android项目,就必须使用AVD manger,这是和SDK manger在统一目录下的可执行文件。

这是用来创建虚拟机的程序,通过这个程序可以在电脑上运行一个Android系统的虚拟机,但是这个程序必须要有加速器程序Haxm,而且还得是6.0及之后的版本才可以。有的电脑已经有了再开启虚拟机的时候就不会报错。没有的需要在官网上下载一份直接安装后就可以解决问题。下载地址为:https://software.intel.com/zh-cn/android/articles/intel-hardware-accelerated-execution-manager

二、Android开发重要部分;

1. Activity

这是用来处理页面数据的部分,是继承Activity类。每一个Activity类都会绑定一个Layout内的一个XML文档,该文档就是显示在Android手机上的页面布局。这些类都是放在src文件夹下的。

2. Layout

在该文件夹下放置的时所有APP的页面文件,格式都是.xml格式。在创建activity的同事Eclipse会自动创建一个.xml 文件放在layout文件夹下;

3. AndroidManifest.xml;

这是用在存储已注册的Activity的文件。所有的Activity类要想正常使用就必须得在这个文件内注册,注册格式如下:

三、Android程序实例;

1. Activity类;

 

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+"用户名不存在或密码错误"+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布局文件;

 

<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="输入账号密码:"
        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="密码"
        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="登录" />

</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. 效果展示;

当出现登录密码错误时,系统提示错误信息;

当账号密码都正确匹配后,界面跳到另一个界面。
 

 

 

  • 大小: 60 KB
  • 大小: 37.3 KB
  • 大小: 70.5 KB
  • 大小: 45.3 KB
分享到:
评论

相关推荐

    Android入门到精通详解(完整书签)

    ### Android入门到精通详解知识点概览 #### 第一篇:Android系统结构和SDK使用 ##### 第1章:Android的系统介绍 - **系统介绍**:Android是Google开发的一款基于Linux平台的开源操作系统,专为移动设备设计。它...

    android 入门PPT大全

    【Android入门PPT大全】是一套专为初学者设计的教育资源,旨在帮助新手快速掌握Android应用开发的基础知识。这套PPT教程涵盖了从Android系统的基本架构到应用程序开发的各个环节,是学习Android开发的理想起点。 ...

    Android入门到精通详解 (带目录)

    这份名为“Android入门到精通详解 (带目录)”的资料全面涵盖了Android开发的基础到高级技术,旨在帮助初学者逐步建立起扎实的技术体系。 首先,从入门阶段开始,你将学习到Android开发环境的搭建,包括安装Java ...

    Android 入门demo源码

    【Android入门Demo源码详解】 Android作为全球最受欢迎的移动操作系统之一,是许多开发者入门编程的首选平台。这个“Android入门demo源码”是专为初学者设计的学习资源,旨在通过实际操作来帮助理解Android开发的...

    android入门学习资料

    《Android入门学习资料详解》 Android作为全球最受欢迎的智能手机操作系统之一,吸引着众多开发者投入其怀抱。本套学习资料旨在帮助初学者快速掌握Android开发的基本技能,内容涵盖Android开发中文文档以及一系列由...

    0基础Android入门项目

    在“0基础Android入门项目”中,初学者可以学习到Android开发的基本概念和技术,这个项目涵盖了几个关键的Android组件和视图。以下是该项目涉及的主要知识点: 1. **登录功能**:登录界面是许多应用程序的基础部分...

    Xamarin.Android 入门(官网)中文文档.pdf

    Xamarin.Android入门文档是面向开发者的一份指南,旨在引导开发者如何开始使用Xamarin.Android进行应用开发。Xamarin.Android是微软公司提供的一个跨平台解决方案的一部分,允许开发者使用C#语言编写原生Android应用...

    Android入门小Demo

    【Android入门小Demo】是一个适合初学者的项目,旨在教授Android应用开发的基础知识。这个小Demo专注于实现一个简单的判断题目功能,用户可以在此应用中回答是或否的问题,系统会根据用户选择判断答案的正误。这个...

    Android入门精通示例源码

    "Android入门精通示例源码"是一个非常适合初学者及进阶者的学习资源,它包含了从基础到高级的各种示例,帮助开发者逐步熟悉并掌握Android应用程序开发的核心技能。 首先,我们要了解Android的基本架构。Android系统...

    android入门到精通.pdf

    《Android入门到精通》这本书是为想要学习和掌握Android应用开发的初学者量身打造的指南。Android作为全球最流行的移动操作系统,拥有庞大的用户群体,为开发者提供了广阔的应用市场和无限的创新空间。本书旨在帮助...

    android 入门学习框架 贪吃蛇小游戏

    在Android入门学习中,贪吃蛇小游戏是一个经典的实践项目,它可以帮助初学者理解Android应用的基本架构、用户界面设计以及事件处理等核心概念。本框架旨在为Android新手提供一个清晰的学习路径,通过实现贪吃蛇游戏...

    android入门学习.ppt

    android入门学习.ppt,对于新手学习android入门有很大的帮助

    android入门快速入门第一天

    "Android入门快速入门第一天"这个主题旨在帮助新接触Android开发的朋友们迅速建立起对这个平台的理解和实践能力。在这个阶段,我们将涵盖以下几个核心知识点: 1. **Android系统概述**:Android是由Google主导的...

    android 入门书籍

    在Android开发领域,入门是每个新手开发者必经的阶段。这份"android 入门书籍"压缩包包含了丰富的学习资源,适合那些对Android编程感兴趣并希望踏入这个领域的初学者。下面,我们将深入探讨这些书籍可能涵盖的关键...

    Android入门到精通知识总结.pdf

    以下是对"Android入门到精通知识总结.pdf"中提及的一些重要概念的详细说明: ### 1. **Activity的生命周期** Activity是Android应用中的核心组件,它代表了用户界面的一个屏幕。Activity有七个主要状态,包括`...

    Android入门中文文档

    Android入门中文文档是一份专为初学者设计的指南,旨在帮助新接触Android开发的朋友们快速理解和掌握这个全球最大的智能手机操作系统的基础知识。这份文档通常包含了从安装开发环境到编写第一个应用程序的所有步骤,...

    完整的android 安卓入门demo

    通过这个完整的Android入门Demo,开发者不仅可以学习到基础控件的使用,还能理解服务和广播的机制,掌握Android应用开发的核心概念。实践中不断练习,将有助于提升Android编程技能,为成为专业开发者奠定坚实基础。

Global site tag (gtag.js) - Google Analytics