[size=large]
android简单学习总结:
在学习android之前,我们必须了解用Ecplice搭建android开发平台;在搭建平台之前、我们需要下载
或拷贝两个文件:ADT-10.0.1 (1)和android-sdk_r06-windows;这两个文件很大,建议向有资源的同学拷
贝;注意:这两个文件要和自己电脑所配置操作系统统一;32位就用32位的、64位的就用64位的;不然后面
配置过程会 出问题的。。。
有了这两个文件后,先安装ADT、安装完后,在电脑属性中的环境变量path中,加入Android的安装目录
/tools。
然后在Ecplice中安装ADT插件;
在安装插件时,需要将目录为ADT-10.0.1 (1)\plugins文件下的四个文件复制到 Ecplice中的
plugins中;这样,安装时才会自动安装;
接着就是安装ADT, 打开Eclipse —> help —> install New Software
点击add按钮,弹出对话框要求输入Name和Location
Name:自己随便取名
Location:输入:Http://dl-ssl.google.com/android/eclipse
点击OK按钮后,在Work with下面的下拉列表中把它们都选中,然后根 据提示往下走
完成以上步骤后,选择Window > Preferences,在左边的面板选择Android,弹出界面后、选择所要
开发的android版本即可。
最后创建AVD(Android Virtual Device)
Android应用程序要在虚拟机上运行,必须创建AVD;
点击Ecplice菜单栏上的"Open android SDK and AVD Manager"按键;
打开界面后,填写SD卡的大小;这个一般是256M,如果需要内存比较大的话,可以适当填大些。。
点击Create AVD完成AVD创建
选中此虚拟机,点击右侧工具栏中的Starts the selected AVD,虚拟手机就开机了
这样,开发的平台就搭建好了。。
下面是开发软件的步骤:
开发项目先了解什么是Activity?
手机开发最重要的是用户接口,Android中的Activity就是Android应用与用户的接口,
Activity是Android中最常用的组件。
从视觉效果来看,一个Activity占据一个窗口界面,响应所有窗口事件,具备有控件,菜单等界面
元素。从内部逻辑来看,Activity需要为了保持各个界面状态,需要做很多持久化的事情,还需要妥善管理
生命周期,和一些转跳逻辑。
这些或许暂时你还不能理解,没关系、我们可以先继续往下走;
这里我们简单介绍登录界面的开发过程:
实现登录界面需先设置按钮及文本输入框布局:
此布局需在main.xml中设置、详细代码如下
[/size]
[size=large]
这样,我们可以点击右键、运行android application;此时可以看到手机模拟器中显现的
按钮和文本输入框布局。
接着、在继承Activity的类中获取组件。。
其代码如下:
[/size]
[size=large]
获取组件后,添加按钮、实现按钮的动作命令;这里、我们可以用匿名内部类来实现。
代码如下:
[/size]
[size=large]
上面、账号和密码匹配后、将进入第二界面;这里将不进行详述。
这样、简单的登录界面功能便实现了。。。
[/size]
android简单学习总结:
在学习android之前,我们必须了解用Ecplice搭建android开发平台;在搭建平台之前、我们需要下载
或拷贝两个文件:ADT-10.0.1 (1)和android-sdk_r06-windows;这两个文件很大,建议向有资源的同学拷
贝;注意:这两个文件要和自己电脑所配置操作系统统一;32位就用32位的、64位的就用64位的;不然后面
配置过程会 出问题的。。。
有了这两个文件后,先安装ADT、安装完后,在电脑属性中的环境变量path中,加入Android的安装目录
/tools。
然后在Ecplice中安装ADT插件;
在安装插件时,需要将目录为ADT-10.0.1 (1)\plugins文件下的四个文件复制到 Ecplice中的
plugins中;这样,安装时才会自动安装;
接着就是安装ADT, 打开Eclipse —> help —> install New Software
点击add按钮,弹出对话框要求输入Name和Location
Name:自己随便取名
Location:输入:Http://dl-ssl.google.com/android/eclipse
点击OK按钮后,在Work with下面的下拉列表中把它们都选中,然后根 据提示往下走
完成以上步骤后,选择Window > Preferences,在左边的面板选择Android,弹出界面后、选择所要
开发的android版本即可。
最后创建AVD(Android Virtual Device)
Android应用程序要在虚拟机上运行,必须创建AVD;
点击Ecplice菜单栏上的"Open android SDK and AVD Manager"按键;
打开界面后,填写SD卡的大小;这个一般是256M,如果需要内存比较大的话,可以适当填大些。。
点击Create AVD完成AVD创建
选中此虚拟机,点击右侧工具栏中的Starts the selected AVD,虚拟手机就开机了
这样,开发的平台就搭建好了。。
下面是开发软件的步骤:
开发项目先了解什么是Activity?
手机开发最重要的是用户接口,Android中的Activity就是Android应用与用户的接口,
Activity是Android中最常用的组件。
从视觉效果来看,一个Activity占据一个窗口界面,响应所有窗口事件,具备有控件,菜单等界面
元素。从内部逻辑来看,Activity需要为了保持各个界面状态,需要做很多持久化的事情,还需要妥善管理
生命周期,和一些转跳逻辑。
这些或许暂时你还不能理解,没关系、我们可以先继续往下走;
这里我们简单介绍登录界面的开发过程:
实现登录界面需先设置按钮及文本输入框布局:
此布局需在main.xml中设置、详细代码如下
[/size]
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:gravity="center_horizontal" android:textSize="30px" android:text="用户登录"/>
<!-- 嵌套布局 -->
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content" android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="账户"/>
<EditText android:layout_height="wrap_content"
android:layout_width="100px"
android:id="@+id/edit_name"/>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content" android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="密码"/>
<EditText android:layout_height="wrap_content"
android:layout_width="100px"
android:id="@+id/edit_pwd"/>
</LinearLayout>
<!-- 按钮对象 -->
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="登陆"
android:id="@+id/btn_login"/>
<Button
android:layout_height="wrap_content"
android:layout_width="100px"
android:text="重置"
android:id="@+id/btn_reset"/>
</LinearLayout>
</LinearLayout>
[size=large]
这样,我们可以点击右键、运行android application;此时可以看到手机模拟器中显现的
按钮和文本输入框布局。
接着、在继承Activity的类中获取组件。。
其代码如下:
[/size]
/** 获取组件的方法 */
public void getView(){
//通过id来找到组件对象
Button btn_login = (Button)findViewById(R.id.btn_login);
Button btn_reset = (Button)findViewById(R.id.btn_reset);
edit_name = (EditText)findViewById(R.id.edit_name);
edit_pwd = (EditText)findViewById(R.id.edit_pwd);
//点击弹出提示信息
btn_login.setOnClickListener(listener);
btn_reset.setOnClickListener(listener);
}
[size=large]
获取组件后,添加按钮、实现按钮的动作命令;这里、我们可以用匿名内部类来实现。
代码如下:
[/size]
/** 创建监听器对象 */
OnClickListener listener = new OnClickListener(){
//监听按钮被点击的操作
public void onClick(View v){
//验证操作
int id = v.getId();
switch(id){
case R.id.btn_login:
//获取文本输入框中的内容
if("netjava".equals(edit_name.getText().toString())){
//创建intent对象,实现界面跳转,intent相当于信使RN
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
//跳转至第二界面
// System.out.println("<><><><><><><><><><>");
startActivity(intent);
}else{
Toast.makeText(FirstActivity.this, "您输入的用户名有误", 3).show();
}
break;
//如果是重置文件
case R.id.btn_reset:
edit_name.setText("");
edit_pwd.setText("");
break;
}
}
};
[size=large]
上面、账号和密码匹配后、将进入第二界面;这里将不进行详述。
这样、简单的登录界面功能便实现了。。。
[/size]