文章目录
- 一、编辑框常用属性
- 二、案例实现
-
- (一)、涉及知识点
- (二)、实现步骤
-
- 1、创建安卓应用【UserRegistration】
- 2、将MainActivity重命名为RegistrationActivity
- 3、将activity_main.xml重命名为activity_regstration.xml
- 4、将两张背景图片拷贝到drawable目录
- 5、基于模板创建InformationActivity
- 6、字符串资源文件strings.xml
- 7、注册界面布局资源文件activity_registration.xml
- 8、显示信息界面布局资源文件activity_information.xml
- 9、用户注册界面类RegistrationActivity
- 10、注册信息显示界面InformationActivity
- 11、启动应用,查看效果
- 三、任务练习(实现乘法运算)
一、编辑框常用属性
text
:文本框的文本内容
maxLines
:最大行数
lines
:行数
inputType
:输入数据类型
hint
:提示
textColor
:文本颜色
textSize
:文本字号
textColorHint
:提示文本颜色
singleLine
:文本是否单行(true, false)
二、案例实现
(一)、涉及知识点
线性布局(LinearLayout
)
标签(TextView
)
编辑框(EditText
)
按钮(Button
)
意图(Intent
)
数据包(Bundle
)
(二)、实现步骤
1、创建安卓应用【UserRegistration】
2、将MainActivity重命名为RegistrationActivity
3、将activity_main.xml重命名为activity_regstration.xml
4、将两张背景图片拷贝到drawable目录
5、基于模板创建InformationActivity
6、字符串资源文件strings.xml
<resources>
<string name="app_name">用户注册</string>
<string name="name">姓名:</string>
<string name="gender">性别:</string>
<string name="age">年龄:</string>
<string name="phone">电话:</string>
<string name="email">邮箱:</string>
<string name="home_page">主页:</string>
<string name="memo">备注:</string>
<string name="register">注册</string>
<string name="cancel">取消</string>
</resources>
7、注册界面布局资源文件activity_registration.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:background="@drawable/reg_bg"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name"
android:textColor="#000000"
android:textSize="16sp" />
<EditText
android:id="@+id/edtName"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/tvGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gender"
android:textColor="#000000"
android:textSize="16sp" />
<EditText
android:id="@+id/edtGender"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/tvAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/age"
android:textColor="#000000"
android:textSize="16sp" />
<EditText
android:id="@+id/edtAge"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/tvPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/phone"
android:textColor="#000000"
android:textSize="16sp" />
<EditText
android:id="@+id/edtPhone"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android