Android 学习之一

   去年4月份开始关注Android 当时由于时间问题只是做了简单的学习,并没有做下笔记。家里办了e9正好送了个ZTE的N600,让我又有了重新学习anDroid的想法,学习历程留下痕迹便于以后翻阅。

 

1. 环境搭建

    这个网上有很多例子,再次不再赘述。

2. 启程Hello Android(做一个 点击按钮 然后弹出一个警告框的示例)

    先看核心代码吧

   

package oms.hello;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class HelloAndroid extends Activity {//一个activity 可以理解为一个页面

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);//设置页面显示的信息
		Button button = (Button) findViewById(R.id.button);//根据ID查找要使用的组建
		button.setOnClickListener(new OnClickListener() {//设置按钮点击时间
			public void onClick(View v) {
				openDialog();//出发按钮点击事件时执行的方法
			}
		});
	}

	private void openDialog() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);//创建警告框对象
		builder.setTitle("Hello");
		builder.setMessage("Hello World \n");
		builder.setNegativeButton("OK", null);
		builder.show();
	}

}

 

3. 组建定义

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="@string/hello" />
	<Button android:id="@+id/button" android:text="@string/click_me"
		android:layout_width="wrap_content" android:layout_height="wrap_content">
	</Button>

	<LinearLayout android:orientation="horizontal"
		android:layout_width="fill_parent" android:layout_height="fill_parent"
		android:layout_weight="1">

		<TextView android:text="red" android:gravity="center_horizontal"
			android:background="#aa0000" android:layout_width="wrap_content"
			android:layout_height="fill_parent" android:layout_weight="1" />

		<TextView android:text="green" android:gravity="center_horizontal"
			android:background="#00aa00" android:layout_width="wrap_content"
			android:layout_height="fill_parent" android:layout_weight="1" />

		<TextView android:text="blue" android:gravity="center_horizontal"
			android:background="#0000aa" android:layout_width="wrap_content"
			android:layout_height="fill_parent" android:layout_weight="1" />

		<TextView android:text="yellow" android:gravity="center_horizontal"
			android:background="#aaaa00" android:layout_width="wrap_content"
			android:layout_height="fill_parent" android:layout_weight="1" />

	</LinearLayout>

	<LinearLayout android:orientation="vertical"
		android:layout_width="fill_parent" android:layout_height="fill_parent"
		android:layout_weight="1">

		<TextView android:text="row one" android:textSize="15pt"
			android:layout_width="fill_parent" android:layout_height="wrap_content"
			android:layout_weight="1" />

		<TextView android:text="row two" android:textSize="15pt"
			android:layout_width="fill_parent" android:layout_height="wrap_content"
			android:layout_weight="1" />

		<TextView android:text="row three" android:textSize="15pt"
			android:layout_width="fill_parent" android:layout_height="wrap_content"
			android:layout_weight="1" />

		<TextView android:text="row four" android:textSize="15pt"
			android:layout_width="fill_parent" android:layout_height="wrap_content"
			android:layout_weight="1" />

	</LinearLayout>
</LinearLayout> 

 

4.  公共资源信息定义

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<string name="hello">Hello World, helloworld!</string>
	<string name="app_name">helloworld</string>
	<string name="click_me">click_me</string>
</resources> 

 

5. 组建

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package oms.hello;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int button=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int click_me=0x7f040002;
        public static final int hello=0x7f040000;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值