题目:购买宝宝装备——Activity知识
本文包括Activity入门、Activity生命周期、Activity启动模式、Intent的使用以及Activity的数据传递。
1,运行结果
1、运行进入界面,输入用户名和密码,点击注册,进入下个界面:
如下图,宝宝的右方会显示刚刚你注册的用户名和密码。(数据传递)
2、再点击立即购买GO!,进入下个界面:
3、宝宝的属性会增加数值。(这里我固定了数值,你也可以进行修改)
4、再次点击页面就返回宝宝购买属性的界面:
并且界面上的数值也增加了,再次点击购买也会叠加。
二,布局文件和class类文件
三,源代码如下
1、注册界面布局文件(activity_main.xml)代码如下:
<?xml version="1.0" encoding="utf-8"?>
<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:background="@drawable/loading"
tools:context=".MainActivity">
<ImageView
android:id="@+id/iv_head"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:src="@drawable/head"/>
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_head"
android:layout_margin="10dp"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/regist_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="用户名:"
android:textSize="20sp"/>
<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/tv_name"
android:hint="请输入用户名"
android:textSize="16sp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/regist_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<TextView
android:id="@+id/tv_psw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="密 码:"
android:textSize="20sp"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/tv_psw"
android:hint="请输入密码"
android:inputType="textPassword"
android:textSize="16sp"/>
</RelativeLayout>
</LinearLayout>
<Button