作业:注册界面及跳转
首先创建两个Activity模板,这里我创建的是
RegisterAc以及 ZCCG ,一个应用于注册界面,另一个应用于注册成功后所跳转的界面。
先把注册的基础界面弄出来,所以先编写创建Activity时生成的layout里所对应的文件。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Re_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Re_name"
android:textColor="#000000"
android:textSize="20sp"/>
<EditText
android:id="@+id/edt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Re_sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Re_sex"
android:textColor="#000000"
android:textSize="20sp"/>
<EditText
android:id="@+id/edt_sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Re_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Re_age"
android:textColor="#000000"
android:textSize="20sp"/>
<EditText
android:id="@+id/edt_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Re_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Re_phone"
android:textColor="#000000"
android:textSize="20sp"/>
<EditText
android:id="@+id/edt_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Re_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Re_email"
android:textColor="#000000"
android:textSize="20sp"/>
<EditText
android:id="@+id/edt_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Re_index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Re_index"
android:textColor="#000000"
android:textSize="20sp"/>
<EditText
android:id="@+id/edt_index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:orientation="horizontal">
<TextView
android:id="@+id/Re_remark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Re_remark"
android:textColor="#000000"
android:textSize="20sp"/>
<EditText
android:id="@+id/edt_remark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="15"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="@+id/btn_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="@string/register"
android:textSize="20sp"/>
<Button
android:id="@+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="@string/cancel"
android:textSize="20sp"/>
</LinearLayout>
然后在Values 的strings里面添加会用到的数据 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210112163229574.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2MjA0MzAy,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210112163235620.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2MjA0MzAy,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210112163248635.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2MjA0MzAy,size_16,color_FFFFFF,t_70) package net.zxj.demo0303;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
public class RegisterAc extends AppCompatActivity {
private EditText edtRename;
private EditText edtResex;
private EditText edtReage;
private EditText edtRephone;
private EditText edtReemail;
private EditText edtReindex;
private EditText edtReremark;
private Button btnRegister;
private Button btnCancel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
//在活动栏显示图标
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setLogo(R.mipmap.ic_launcher);
edtRename =findViewById(R.id.edt_name);
edtResex = findViewById(R.id.edt_sex);
edtReage = findViewById(R.id.edt_age);
edtRephone = findViewById(R.id.edt_phone);
edtReemail = findViewById(R.id.edt_email);
edtReindex = findViewById(R.id.edt_index);
edtReremark = findViewById(R.id.edt_remark);
btnRegister = findViewById(R.id.btn_register);
btnCancel = findViewById(R.id.btn_cancel);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String strRename = edtRename.getText().toString().trim();
String strResex = edtResex.getText().toString().trim();
String strReage = edtReage.getText().toString().trim();
String strRephone = edtRephone.getText().toString().trim();
String strReemail = edtReemail.getText().toString().trim();
String strReremark = edtReremark.getText().toString().trim();
String strReindex = edtReindex.getText().toString().trim();
Intent intentRe = new Intent(RegisterAc.this,ZCCG.class);
//创建数据包,封装数据
Bundle re =new Bundle();
re.putString("Rename",strRename);
re.putString("Reage",strReage);
re.putString("Rephone",strRephone);
re.putString("Reemail",strReemail);
re.putString("Reremark",strReremark);
re.putString("Resex",strResex);
re.putString("Reindex",strReindex);
//通过意图启动目标组件
intentRe.putExtras(re);
startActivity(intentRe);
}
});
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}