注册页面及注册测试

自己慢慢敲得注册页面及注册测试

目前没有实现与数据库的联系

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".RegisterActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账  号:"
            android:textSize="25sp"/>

        <EditText
            android:id="@+id/et_account"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入用户名或手机号"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/edit_text_bg"
            android:inputType="text"
            android:paddingLeft="5dp"
            />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密  码:"
            android:textSize="25sp"/>

        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入密码"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/edit_text_bg"
            android:inputType="textPassword"
            android:paddingLeft="5dp"
            />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="确认密码:"
            android:textSize="25sp"/>

        <EditText
            android:id="@+id/et_password_confirm"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="再次输入密码"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/edit_text_bg"
            android:inputType="textPassword"
            android:paddingLeft="5dp"
            />
    </LinearLayout>


    <Button
        android:id="@+id/btn_register"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        android:textSize="25sp"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:textColor="@color/white"
        android:background="@drawable/btn_bg_selector"/>

    <CheckBox
        android:id="@+id/cb_agree"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:text="还没有账号?"
        android:layout_gravity="left"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"/>

</LinearLayout>

  

package com.example.logintest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btnRegister;
    private EditText etAccount, etPass,etPassConfirm;
    private CheckBox cbAgree;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        getSupportActionBar().setTitle("注册");

        btnRegister = findViewById(R.id.btn_register);
        etAccount = findViewById(R.id.et_account);
        etPass = findViewById(R.id.et_password);
        etPassConfirm = findViewById(R.id.et_password_confirm);
        cbAgree=findViewById(R.id.cb_agree);

        btnRegister.setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {
        String name=etAccount.getText().toString();
        String pass=etPass.getText().toString();
        String passConfirm=etPassConfirm.getText().toString();

        if(TextUtils.isEmpty(name)){
            Toast.makeText(RegisterActivity.this,"用户名不能为空",Toast.LENGTH_LONG).show();
            return;
        }

        if(TextUtils.isEmpty(pass)){
            Toast.makeText(RegisterActivity.this,"密码不能为空",Toast.LENGTH_LONG).show();
            return;
        }

        if(!TextUtils.equals(pass,passConfirm)){
            Toast.makeText(RegisterActivity.this,"密码不一致",Toast.LENGTH_LONG).show();
            return;
        }

        if(!cbAgree.isChecked()){
            Toast.makeText(RegisterActivity.this,"请同意用户协议",Toast.LENGTH_LONG).show();
            return;
        }

        Toast.makeText(RegisterActivity.this,"注册成功",Toast.LENGTH_LONG).show();


    }
}

  

posted @ 2023-03-01 20:14  一统天下。  阅读(20)  评论(0编辑  收藏  举报