Android的HelloWorld
来源:互联网 发布:应用统计学与大数据 编辑:程序博客网 时间:2024/06/18 08:42
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>
- android的helloworld
- Android的helloworld程序
- 开始android的HelloWorld
- Android的HelloWorld
- Phonegap-Android的HelloWorld
- Android的HelloWorld
- android Phonegap项目的HelloWorld
- Android 4.4.2 的helloworld
- Android - HelloWorld的Layout内容
- [Android学习笔记一]Android的HelloWorld
- Android HelloWorld
- android helloworld
- Android helloworld
- android helloworld
- Android helloWorld
- Android HelloWorld
- Android--HelloWorld
- android helloworld
- linux的7种运行级别
- C# DataGridView
- APP接入微信支付步骤,及遇到的问题
- 【转载】python json
- 杭电1034 Candy Sharing Game
- Android的HelloWorld
- 提高Interface Builder高效工作的8个技巧
- Lucene入门实例
- 远程连接另一个主机上的MongoDB数据库服务器
- web自动化(5)----selenium运行JavaScript代码
- ZOJ 3623 Battle Ships 造战舰炸塔 动态规划 伪装较好的完全背包 ★★★
- csu1569: Wet Tiles
- 设置VMWARE通过桥接方式使用主机无线网卡上网
- Ubuntu11.10vim+Ctags+Taglist+WinManager工具的安装