1:学习安卓主要学习安卓的四个最重要的部分:
(1)Activity 每一个应用程序都是Activity
(2)Intent 在不同的Activity之间进行数据传递,以及不同应用的Activity之间进行数据的传递
(3)Service 服务端
(4)Content Provider 主要提供统一的数据访问接口,为其它的应用程序提供数据
(5) BroadCast 广播机制
搭建Android开发平台
我使用的是Android5.0的开发平台,下载集成好了的开发环境,进本上不需要进行额外的配置。
写一个Android的第一个程序HelloWorld
首先介绍一下就是,每一个Activity都对应一个layout布局文件
我们的java程序通过使用R.java来映射整个布局文件 例如R.layout.*** R.string.***
最重要的配置文件是AndroidMainfest.xml文件,该文件主要是配置Activity的
package com.example.helloworld;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
/*
* Activity的第一讲
* 创建一个Activity的注意几个事项
* 1该Activity extends ActionBarActivity
* 2重写父类的方法onCreate()
* 3每一个Activity都需要在AndroidMainfest中手动的注册
* 4为Activity添加控件
* */
/*
* Activity的第二讲
* 主要就是多个Activity之间的通信,主要是使用Intent 对象进行通信。多个Activity可以在一个应用
* */
public class Activity01 extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
系统在加在玩
setContentView(R.layout.activity01);
TextView textview=(TextView)findViewById(R.id.tvUserName);
Button button=(Button)findViewById(R.id.bLogin);
textview.setText("我的第一个TextView");
button.setText("我的第一个按钮");
button.setOnClickListener(new MyButtonOnClickListener());
}
class MyButtonOnClickListener implements OnClickListener{
@Override
public void onClick(View view) {
Intent myintent=new Intent();
myintent.putExtra("testIntent", "1234");
myintent.setClass(Activity01.this, Activity02.class);
Activity01.this.startActivity(myintent);
}
}
}
activity01.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/username"
android:textSize="30sp"
/>
<Button
android:id="@+id/bLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@id/tvUserName"
android:text="@string/login"
android:textSize="30sp"
android:textColor="#000"
/>
</LinearLayout>
activity02.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvOther"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvOther"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>