本文是用来介绍android studio创建注册页面跳转登录页面的界面设计以及跳转功能地实现,完整结构见文章结尾。

用户注册界面

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".mainactivity">
<!---->
<!---->
    <textview
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginleft="30dp"
        android:layout_margintop="30dp"
        android:text="用户名:"
        app:layout_constraintbottom_tobottomof="parent"
        app:layout_constrainthorizontal_bias="0.047"
        app:layout_constraintleft_toleftof="parent"
        app:layout_constraintright_torightof="parent"
        app:layout_constrainttop_totopof="parent"
        app:layout_constraintvertical_bias="0.064" />
    <edittext
        android:id="@+id/et1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginstart="16dp"
        android:layout_marginleft="16dp"
        android:layout_margintop="72dp"
        android:ems="10"
        android:hint="请输入你的用户名"
        android:inputtype="textpersonname"
        app:layout_constraintstart_toendof="@+id/textview"
        app:layout_constrainttop_totopof="parent" />
    <textview
        android:id="@+id/textview2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginstart="56dp"
        android:layout_marginleft="56dp"
        android:layout_margintop="28dp"
        android:text="密码:"
        app:layout_constraintstart_tostartof="parent"
        app:layout_constrainttop_tobottomof="@+id/et1" />
    <edittext
        android:id="@+id/et2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginstart="20dp"
        android:layout_marginleft="20dp"
        android:layout_margintop="30dp"
        android:ems="10"
        android:hint="请输入你的密码"
        android:inputtype="textpassword"
        app:layout_constraintstart_toendof="@+id/textview2"
        app:layout_constrainttop_tobottomof="@+id/et1" />
    <textview
        android:id="@+id/textview3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginstart="28dp"
        android:layout_marginleft="28dp"
        android:layout_margintop="24dp"
        android:text="性别"
        app:layout_constraintstart_tostartof="parent"
        app:layout_constrainttop_tobottomof="@+id/et2" />
    <radiogroup
        android:id="@+id/rg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginstart="30dp"
        android:layout_marginleft="30dp"
        android:layout_margintop="60dp"
        android:orientation="horizontal"
        app:layout_constraintstart_tostartof="parent"
        app:layout_constrainttop_tobottomof="@+id/et2">
        <radiobutton
            android:id="@+id/rb1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="男" />
        <radiobutton
            android:id="@+id/rb2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="女" />
    </radiogroup>
    <textview
        android:id="@+id/textview4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginstart="30dp"
        android:layout_marginleft="30dp"
        android:layout_margintop="30dp"
        android:text="兴趣爱好"
        app:layout_constraintstart_tostartof="parent"
        app:layout_constrainttop_tobottomof="@+id/rg" />
    <checkbox
        android:id="@+id/cb1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginstart="28dp"
        android:layout_marginleft="28dp"
        android:layout_margintop="16dp"
        android:text="游戏编程"
        app:layout_constraintstart_tostartof="parent"
        app:layout_constrainttop_tobottomof="@+id/textview4" />
    <checkbox
        android:id="@+id/cb2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginstart="28dp"
        android:layout_marginleft="28dp"
        android:text="王者荣耀"
        app:layout_constraintstart_tostartof="parent"
        app:layout_constrainttop_tobottomof="@+id/cb1" />
    <checkbox
        android:id="@+id/cb3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginstart="28dp"
        android:layout_marginleft="28dp"
        android:text="看《觉醒年代》"
        app:layout_constraintstart_tostartof="parent"
        app:layout_constrainttop_tobottomof="@+id/cb2" />
    <button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margintop="36dp"
        android:text="注册"
        app:layout_constraintend_toendof="parent"
        app:layout_constrainthorizontal_bias="0.498"
        app:layout_constraintstart_tostartof="parent"
        app:layout_constrainttop_tobottomof="@+id/cb3" />
    <textview
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margintop="40dp"
        android:text="执行结果"
        app:layout_constraintend_toendof="parent"
        app:layout_constraintstart_tostartof="parent"
        app:layout_constrainttop_tobottomof="@+id/button" />
</androidx.constraintlayout.widget.constraintlayout>

用户登录界面

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:xmlna="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#f1eaf3">
        <com.example.myapplication1.titlelayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    <textview
        android:layout_width="fill_parent"
        android:layout_height="90dp"
        android:text="登 录 界 面"
        android:textcolor="#232121"
        android:textsize="40dp"
        android:gravity="center">
    </textview>
    <linearlayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#f1eaf3"
        android:paddingleft="5dip"
        android:paddingright="5dip"
        android:paddingtop="5dip">
        <linearlayout
            android:id="@+id/linearlayout1"
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <textview
                android:id="@+id/textview2"
                android:layout_width="wrap_content"
                android:layout_height="40dip"
                android:layout_marginleft="5dip"
                android:textsize="23dip"
                android:gravity="center_vertical"
                android:background="#f0e1f3"
                android:text="用户名:">
            </textview>
            <edittext
                android:id="@+id/edittextuid"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:singleline="true"
                android:layout_marginleft="0dip"
                android:text=""
                android:textsize="23dip">
            </edittext>
        </linearlayout>
        <linearlayout
            android:id="@+id/linearlayout2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <textview
                android:id="@+id/textview3"
                android:layout_width="wrap_content"
                android:layout_height="40dip"
                android:layout_marginleft="5dip"
                android:textsize="23dip"
                android:gravity="center_vertical"
                android:background="#f0e1f3"
                android:text="密     码:">
            </textview>
            <edittext
                android:id="@+id/edittextpwd"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:singleline="true"
                android:text="ling"
                android:textsize="23dip">
            </edittext>
        </linearlayout>
        <linearlayout
            android:id="@+id/linearlayout3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <button
                android:id="@+id/loginlog"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textsize="23dip"
                android:background="#e8ccea"
                android:layout_weight="1"
                android:text="登   录">
            </button>
            <button
                android:id="@+id/loginclear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textsize="23dip"
                android:background="#d1b8d3"
                android:layout_weight="1"
                android:text="清   空">
            </button>
        </linearlayout>
    </linearlayout>
    <textview
        android:id="@+id/all"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="欢迎"
        android:textsize="20sp"/>
</linearlayout>

java代码实现跳转

package com.example.myapplication1;
import android.content.intent;
import android.os.bundle;
import android.view.view;
import android.widget.button;
import android.widget.checkbox;
import android.widget.compoundbutton;
import android.widget.edittext;
import android.widget.radiobutton;
import android.widget.radiogroup;
import android.widget.textview;
import androidx.appcompat.app.actionbar;
import androidx.appcompat.app.appcompatactivity;
public class mainactivity extends appcompatactivity implements view.onclicklistener,radiogroup.oncheckedchangelistener, compoundbutton.oncheckedchangelistener{
    private button zc;//声明注册按钮的变量
    radiogroup rg;//声明单选组的变量
    radiobutton rb1,rb2;//声明单选1,单选2的变量
    checkbox cb1,cb2,cb3;//声明复选框1,2,3的变量
    edittext et1,et2;声明输入文本框1,2的变量
    textview tv,txtage,txtall;//声明结果文本的变量
    @override
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.activity_main);
        //屏蔽系统自带
        actionbar actionbar = getsupportactionbar();
        if(actionbar != null){
            actionbar.hide();}
        zc=findviewbyid(r.id.button);//寻找注册按钮id
        zc.setonclicklistener(this);//给注册按钮安装监听器
        rg=findviewbyid(r.id.rg);//寻找单选组控件id
        rg.setoncheckedchangelistener(this);//给单选组安装监听器
        rb1=findviewbyid(r.id.rb1);//寻找单选控件1id
        rb1.setoncheckedchangelistener(this);//给单选控件1安装监听器
        rb2=findviewbyid(r.id.rb2);//寻找单选控件2id
        rb2.setoncheckedchangelistener(this);//给单选控件2安装监听器
        //txtage=(textview)findviewbyid(r.id.age);
        cb1=findviewbyid(r.id.cb1);//寻找复选框1控件id
        cb1.setoncheckedchangelistener(this);//给复选框控件1安装监听器
        cb2=findviewbyid(r.id.cb2);//寻找复选框2控件id
        cb2.setoncheckedchangelistener(this);//给复选框控件2安装监听器
        cb3=findviewbyid(r.id.cb3);//寻找复选框3控件id
        cb3.setoncheckedchangelistener(this);//给复选框控件3安装监听器
        et1=findviewbyid(r.id.et1);//寻找输入框1控件id
        et2=findviewbyid(r.id.et2);//寻找输入框2控件id
        tv=findviewbyid(r.id.tv);//寻找输入框2控件id
    }
    //实现选项按钮组交互功能
    @override
    public void oncheckedchanged(radiogroup group, int checkedid) {
        switch (checkedid){
            case r.id.rb1:
                system.out.println(rb1.gettext().tostring());
                break;
            case r.id.rb2:
                system.out.println(rb2.gettext().tostring());
                break;
        }
    }
    //实现复选框交互功能
    @override                      //compoundbutton选中或未选中按钮
    public void oncheckedchanged(compoundbutton compoundbutton, boolean b) {
        switch (compoundbutton.getid()) //得到选中或未选中按钮id
        {
            case r.id.cb1: //复选框1id
                if (b==true)//判断复选框1是否为真
                    system.out.println(cb1.gettext().tostring());
                //如果是真执行复选框按钮输出的结果是得到该文本(cb1对应的text属性文本字符串)字符串
                break;
            case r.id.cb2:
                if (b==true)
                    system.out.println(cb2.gettext().tostring());
                break;
            case r.id.cb3:
                if (b==true)
                    system.out.println(cb3.gettext().tostring());
                break;
        }
    }
    //注册按钮实现交互功能
    @override
    public void  onclick(view view){
        string strname=et1.gettext().tostring();//获取用户名(id绑定用户名)
        string strpassword=et2.gettext().tostring();//获取密码(id绑定密码)
        //
                int age;
                charsequence str="";
                if(rb1.ischecked())
                    str=rb1.gettext();
                if(rb2.ischecked())
                    str=rb2.gettext();
                string str1="";
                if (cb1.ischecked()) str1=str1+"\n"+cb1.gettext();
                if (cb2.ischecked()) str1=str1+"\n"+cb2.gettext();
                if (cb3.ischecked()) str1=str1+"\n"+cb3.gettext();
        //
        if (strname.equals(" ")||strpassword.equals(""))//判断用户名是否等于""并且满足密码等于""
            tv.settext("注册失败,请重新修改信息后再来注册");//否则执行结果文本框输出内容为"注册失败,请重新修改信息后再来注册"
        else
        {
            tv.settext(strname+"注册成功");//如果满足条件的话执行结果文本框输出内容为"注册成功"
             intent intent=new intent(mainactivity.this, success.class);
             intent.putextra("strname",strname);
             intent.putextra("strpassword",strpassword);
            //intent.putextra("strname",strname);
            intent.putextra("sex",str);
            intent.putextra("str1",str1);
            startactivity(intent);
        }
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。