Android注册登录页面1:https://developer.aliyun.com/article/1473210
Result.java
package top.gaojc.app; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import top.gaojc.app.domain.UserInfo; public class Result extends AppCompatActivity { // 初始化 // 返回值 TextView result; // 登录按钮 Button login; // 账号 String zhanghao; // 密码 String mima; // 昵称 String nicheng; // 性别 String xingbie; // 爱好 String aihao; // 简介 String jianjie; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_result); // 绑定 result = findViewById(R.id.tv_result); login = findViewById(R.id.btn_login); // 用户信息对象 UserInfo userInfo = new UserInfo(); // 获取用户信息 zhanghao = userInfo.getZhanghao(); mima = userInfo.getMima(); nicheng = userInfo.getNicheng(); xingbie = userInfo.getXingbie(); aihao = userInfo.getAihao(); jianjie = userInfo.getJianjie(); // 设置显示的数据 result.setText("账号:" + zhanghao + "\n密码:" + mima + "\n昵称:" + nicheng + "\n性别:" + xingbie + "\n爱好:" + aihao + "\n简介:" + jianjie); // 监听事件 login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Result.this, Login.class); startActivity(intent); } }); } }
Welcome.java
package top.gaojc.app; import android.os.Bundle; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import top.gaojc.app.domain.UserInfo; public class Welcome extends AppCompatActivity { // 初始化 TextView register; String nicheng; String xingbie; // 称谓 先生 or 女士 String appellation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); // 绑定 register = findViewById(R.id.tv_register); // 获取用户的昵称和性别 UserInfo userInfo = new UserInfo(); nicheng = userInfo.getNicheng(); xingbie = userInfo.getXingbie(); // 判断男女 昵称后面跟称谓 if (xingbie.equals("男")){ appellation = "先生"; }else { appellation = "女士"; } // 输出内容的拼接 String text = "欢迎" + nicheng + appellation + "!"; // 打印 register.setText(text); } }
.xml
activity_login.xml
<?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" tools:context=".Login" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户登录" android:layout_gravity="center" android:textSize="25sp"/> <TextView android:id="@+id/txt" android:layout_width="match_parent" android:layout_height="48dp" android:gravity="center" android:layout_centerInParent="true" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账号" /> <EditText android:id="@+id/account" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword"/> </LinearLayout> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="登录"/> </LinearLayout>
activity_main.xml
<?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" tools:context=".MainActivity" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户注册" android:layout_gravity="center" android:textSize="25sp"/> <TextView android:id="@+id/txt" android:layout_width="match_parent" android:layout_height="48dp" android:gravity="center" android:layout_centerInParent="true" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账号" /> <EditText android:id="@+id/edt_account" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码" /> <EditText android:id="@+id/edt_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确认密码" /> <EditText android:id="@+id/edt_confirmPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="昵称" /> <EditText android:id="@+id/edt_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true"/> </LinearLayout> <RadioGroup android:id="@+id/rg_gender" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性别"/> <RadioButton android:id="@+id/rb_man" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" android:checked="true"/> <RadioButton android:id="@+id/rb_woman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女"/> </RadioGroup> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="爱好"/> <CheckBox android:id="@+id/cb_eat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="吃"/> <CheckBox android:id="@+id/cb_drink" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="喝" /> <CheckBox android:id="@+id/cb_play" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="玩"/> <CheckBox android:id="@+id/cb_happy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="乐"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="简介" /> <EditText android:id="@+id/edt_presentation" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true"/> </LinearLayout> <Button android:id="@+id/btn_register" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册" android:layout_gravity="center" android:textSize="20sp" android:layout_marginTop="35dp"/> </LinearLayout>
activity_result.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".Result"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="注册成功!" android:layout_above="@id/tv_result" android:layout_centerHorizontal="true" android:textColor="#00ff99" android:textSize="30sp"/> <!-- 返回内容--> <TextView android:id="@+id/tv_result" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"/> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tv_result" android:layout_centerHorizontal="true" android:text="去登录"/> </RelativeLayout>
activity_result.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".Welcome"> <TextView android:id="@+id/tv_register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="30sp"/> </RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="top.gaojc.app"> <application android:allowBackup="true" android:icon="@drawable/wyy" android:label="@string/app_name" android:roundIcon="@drawable/wyy" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".Login"/> <activity android:name=".Result" /> <activity android:name=".Welcome" /> <activity android:name=".domain.UserInfo"/> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
页面效果
注册页面
注册成功页面
登录页面
登录成功页面