安卓如何书写注册和登录界面
一、如何跳转一个活动
左边的是本活动名称, 右边的是跳转界面活动名称
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
finish();
二、如果在不同的界面传递参数
//发送消息
SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.apply(); //接收消息
SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs", MODE_PRIVATE);
String savedUsername = sharedPreferences.getString("username", "");
String savedPassword = sharedPreferences.getString("password", "");
三、如何让图片是按钮
<ImageButtonandroid:id="@+id/imageButton"android:layout_width="50dp"android:layout_height="50dp"android:src="@drawable/s7" />
四、登录界面
1、创建一个LoginActivity类,然后创建对应的界面文件.xml
2、注册登录界面,并让登录界面其成为主界面
<activityandroid:name=".LoginActivity"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".MainActivity"/><activity android:name=".RegisterActivity"/>
3、书写登录界面
<?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:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="20dp"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="账号:"android:textSize="20dp"/><EditTextandroid:id="@+id/usernameEditText"android:layout_width="180dp"android:layout_height="wrap_content"android:textSize="20dp"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="密码:"android:textSize="20dp"/><EditTextandroid:id="@+id/passwordEditText"android:layout_width="180dp"android:layout_height="wrap_content"android:textSize="20dp"/></LinearLayout><TextViewandroid:layout_width="wrap_content"android:layout_height="20dp"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center"><CheckBoxandroid:id="@+id/rememberPasswordCheckbox"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="记住密码"android:layout_gravity="start"android:layout_marginStart="16dp"android:layout_marginTop="8dp"/><TextViewandroid:layout_width="80dp"android:layout_height="wrap_content"/><Buttonandroid:id="@+id/zcButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="点击注册" /></LinearLayout><TextViewandroid:layout_width="wrap_content"android:layout_height="20dp"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center"><Buttonandroid:id="@+id/loginButton"android:layout_width="200dp"android:layout_height="wrap_content"android:text="确认登录" /></LinearLayout></LinearLayout>
4、书写登录活动代码
package com.example.yaodian;import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
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.Toast;import androidx.appcompat.app.AppCompatActivity;public class LoginActivity extends AppCompatActivity {EditText usernameEditText;EditText passwordEditText;Button loginButton;Button zcButton;CheckBox rememberPasswordCheckbox ;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.login);rememberPasswordCheckbox = findViewById(R.id.rememberPasswordCheckbox);usernameEditText = findViewById(R.id.usernameEditText);passwordEditText = findViewById(R.id.passwordEditText);loginButton = findViewById(R.id.loginButton);zcButton = findViewById(R.id.zcButton);loginButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {String inputUsername = usernameEditText.getText().toString();String inputPassword = passwordEditText.getText().toString();SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs", MODE_PRIVATE);String savedUsername = sharedPreferences.getString("username", "");String savedPassword = sharedPreferences.getString("password", "");// 在这里添加登录验证逻辑if (inputUsername.equals(savedUsername) && inputPassword.equals(savedPassword)) {Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show();Intent intent = new Intent(LoginActivity.this, MainActivity.class);startActivity(intent);finish();// 跳转到 MainActivity 或其他操作} else {new AlertDialog.Builder(LoginActivity.this).setTitle("提示").setMessage("登录失败,用户名或密码错误").setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {}}).show();}}});zcButton.setOnClickListener((l) -> {Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);startActivity(intent);finish();});// // 监听复选框状态变化
// rememberPasswordCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
// @Override
// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// // 根据复选框状态来处理记住密码逻辑
// if (isChecked) {
//
// } else {
//
// }
// }
// });}
}
五、注册界面
同登录界面
<?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:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="20dp"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text=" 账号:"android:textSize="20dp"/><EditTextandroid:id="@+id/usernameEditText"android:layout_width="180dp"android:layout_height="wrap_content"android:textSize="20dp"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text=" 密码:"android:textSize="20dp"/><EditTextandroid:id="@+id/passwordEditText"android:layout_width="180dp"android:layout_height="wrap_content"android:textSize="20dp"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="确认密码:"android:textSize="20dp"/><EditTextandroid:id="@+id/password2EditText"android:layout_width="180dp"android:layout_height="wrap_content"android:textSize="20dp"/></LinearLayout><TextViewandroid:layout_width="wrap_content"android:layout_height="50dp"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="center"><Buttonandroid:id="@+id/registerButton"android:layout_width="200dp"android:layout_height="wrap_content"android:text="确认注册" /></LinearLayout></LinearLayout>
package com.example.yaodian;import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;public class RegisterActivity extends AppCompatActivity {private EditText usernameEditText;private EditText passwordEditText;private EditText password2EditText;private Button registerButton;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.register_activity);usernameEditText = findViewById(R.id.usernameEditText);passwordEditText = findViewById(R.id.passwordEditText);password2EditText = findViewById(R.id.password2EditText);registerButton = findViewById(R.id.registerButton);registerButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {String username = usernameEditText.getText().toString().trim();String password = passwordEditText.getText().toString().trim();String password2 = password2EditText.getText().toString().trim();if (username.isEmpty() || password.isEmpty()) {// 弹出“请输入账号和密码”的对话框new AlertDialog.Builder(RegisterActivity.this).setTitle("提示").setMessage("请输入账号和密码").setPositiveButton("确定", null).show();} else if (!password.equals(password2)) {// 弹出“两次密码不一样,请重新输入”的对话框new AlertDialog.Builder(RegisterActivity.this).setTitle("提示").setMessage("两次密码不一样,请重新输入").setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// 清空密码和确认密码输入框passwordEditText.setText("");password2EditText.setText("");}}).show();} else {// 保存注册信息到 SharedPreferencesSharedPreferences sharedPreferences = getSharedPreferences("MyPrefs", MODE_PRIVATE);SharedPreferences.Editor editor = sharedPreferences.edit();editor.putString("username", username);editor.putString("password", password);editor.apply();Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);startActivity(intent);finish();}}});}
}
六、完整工程代码
链接:https://pan.baidu.com/s/13tm-AsAsJEmfJjbwyX0a3Q
提取码:生日
需要提取码的 加QQ:1482728006,说明来意,付费即可获取工程
相关文章:

安卓如何书写注册和登录界面
一、如何跳转一个活动 左边的是本活动名称, 右边的是跳转界面活动名称 Intent intent new Intent(LoginActivity.this, RegisterActivity.class); startActivity(intent); finish(); 二、如果在不同的界面传递参数 //发送消息 SharedPreferences sharedPreferen…...

黄仁勋的AI时代:英伟达GPU革命的狂欢与挑战
在最近的COMPUTEX 2024大会上,英伟达创始人黄仁勋发布了最新的Blackwell GPU。这次发布不仅标志着英伟达在AI领域的又一次飞跃,也展示了其对未来技术发展的战略规划。本文将详细解析英伟达最新技术的亮点,探讨其在AI时代的市场地位和未来挑战…...

Linux云计算架构师涨薪班课程内容包含哪些?
第一阶段:Linux云计算运维初级工程师 目标 云计算工程师,Linux运维工程师都必须掌握Linux的基本功,这是一切的根本,必须全部掌握,非常重要,有了这些基础,学习上层业务和云计算等都非常快&#x…...

c语言:自定义类型(枚举、联合体)
前言: c语言中中自定义类型不仅有结构体,还有枚举、联合体等类型,上一期我们详细讲解了结构体的初始化,使用,传参和内存对齐等知识,这一期我们来介绍c语言中的其他自定义类型枚举和联合体的知识。 1.位段 …...

2024年适合GISer参加的全国性比赛
作为一名GISer,在校期间参加GIS比赛,不仅能够锻炼和提升自己的GIS专业水平,例如软件操作、开发能力等;还能加强自己团队协作能力、组织能力和沟通能力,此外,还可以给简历加分,增强职场竞争力。 …...

番外篇-用户购物偏好标签BP-推荐算法ALS
引言 推荐系统式信息过载所采用的措施,面对海量的数据信息,从中快速推荐出符合用户特点的物品。 推荐系统是自动化的通过分析用户对历史行为数据,完成用户的个性化建模,从而主动给用户推荐能够满足他们兴趣和需求的软件系统。 数…...

气膜体育馆的防火性能分析—轻空间
随着现代体育事业的蓬勃发展,气膜体育馆因其建设快捷、成本低廉、使用灵活等优势,逐渐在全球范围内受到广泛关注。然而,对于这种新型建筑形式,防火性能一直是人们关注的焦点之一。轻空间将详细探讨气膜体育馆的防火性能࿰…...

什么台灯对眼睛好?一文给你分享具体什么台灯对眼睛好!
什么台灯对眼睛好?随着学生们最近陆续返校,家长们和孩子们都忙于开学初的准备工作,而眼睛的健康自然也是他们考虑的一部分。这也是护眼台灯在近年来变得非常普及的原因之一。我自己一直是一个近视的人,而且日常用眼时间也相当长。…...
python-bert模型基础笔记0.1.00
python-bert模型基础笔记0.1.00 bert的适合的场景bert多语言和中文模型bert模型两大类官方建议模型模型中名字的含义标题bert系列模型包含的文件bert系列模型参数参考链接bert的适合的场景 裸跑都非常优秀,句子级别(例如,SST-2)、句子对级别(例如MultiNLI)、单词级别(例…...

STM32G030C8T6:EEPROM读写实验(I2C通信)--M24C64
本专栏记录STM32开发各个功能的详细过程,方便自己后续查看,当然也供正在入门STM32单片机的兄弟们参考; 本小节的目标是,系统主频64 MHZ,采用高速外部晶振,实现PB11,PB10 引脚模拟I2C 时序,对M24C08 的EEPRO…...
opencascade 布尔运算笔记
BRepAlgoAPI_Common 对两个topods求解 没有公共部分也返回结果了 我想要的结果是没有公共部分返回false 在 Open CASCADE 中使用 BRepAlgoAPI_Common 进行布尔操作时,即使两个 TopoDS_Shape 没有公共部分,操作仍会返回一个结果。为了判断两个形状是否确…...

GPT-4o:人工智能新纪元的突破与展望
💝💝💝欢迎来到我的博客,很高兴能够在这里和您见面!希望您在这里可以感受到一份轻松愉快的氛围,不仅可以获得有趣的内容和知识,也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…...

标准化、信息化、数字化、智能化、智慧化与数智化
近年来,标准化、信息化、数字化、智能化、智慧化以及数智化等词汇频繁出现,并逐渐成为业界热议的焦点。在国内,以华为、BAT等为代表的领军企业,不断强调“数字化转型”的重要性,并致力于推动其深入实施。与此同时&…...
14-JavaScript中的点操作符与方括号操作符
JavaScript中的点操作符与方括号操作符:简单理解与应用 笔记分享 在JavaScript中,访问对象的属性有两种常见方式:点操作符(.)和方括号操作符([])。尽管它们在很多情况下可以互换使用࿰…...

智慧大屏是如何实现数据可视化的?
智慧大屏,作为数据可视化的重要载体,已在城市管理、交通监控、商业运营等领域广泛应用。本文旨在阐述智慧大屏实现数据可视化的关键技术和方法,包括数据源管理、数据处理、视觉编码、用户界面与交互设计等。 大屏通过接入企业内部的数据库系…...

【JVM精通之路】垃圾回收-三色标记算法
首先预期你已经基本了解垃圾回收的相关知识,包括新生代垃圾回收器,老年代垃圾回收器,以及他们的算法,可达性分析等等。 先想象一个场景 最开始黑色节点是GC-Roots的根节点,这些对象有这样的特点因此被选为垃圾回收的根…...

Redis缓存(笔记一:缓存介绍和数据库启动)
目录 1、NoSQL数据库简介 2、Redis介绍 3、Redis(win系统、linux系统中操作) 3.1 win版本Redis启动 3.2 linux版本Redis启动 1、NoSQL数据库简介 技术的分类:(发展史) 1、解决功能性的问题:Java、Jsp、RDBMS、Tomcat、HTML、…...

OrangePi Kunpeng Pro套装测评:开箱与基本功能测试
前言 大家好,我是起个网名真难。非常荣幸受到香橙派的邀请,同时也是第一次做这个事情,很荣幸对香橙派与华为鲲鹏在2024年5月12日联合发布的新品——香橙派Kunpeng Pro开发板进行深入的评测。这款开发板是香橙派与华为鲲鹏合作推出的高性能平…...
RocketMQ教程(二):RocketMQ以及控制台的安装
RocketMQ-Console RocketMQ-Console 是一个针对 Apache RocketMQ 的开源 Web 监控和管理平台。它提供了一个用户友好的界面,通过 Web 浏览器允许用户对 RocketMQ 集群进行管理和监控。这个控制台使得管理和监测 RocketMQ 集群变得更加直观和方便,特别是对于不熟悉命令行操作的…...

电脑记事本怎么恢复之前的内容记录
每个人都曾有过这样的时刻——在记事本上精心记录下的重要内容,一不小心就被删除了。那种心情,仿佛一瞬间从山顶跌落到谷底,无尽的懊悔涌上心头。我也曾遭遇过这样的困境,那些消失的文字对我来说意义非凡,它们的丢失仿…...

docker详细操作--未完待续
docker介绍 docker官网: Docker:加速容器应用程序开发 harbor官网:Harbor - Harbor 中文 使用docker加速器: Docker镜像极速下载服务 - 毫秒镜像 是什么 Docker 是一种开源的容器化平台,用于将应用程序及其依赖项(如库、运行时环…...
Golang 面试经典题:map 的 key 可以是什么类型?哪些不可以?
Golang 面试经典题:map 的 key 可以是什么类型?哪些不可以? 在 Golang 的面试中,map 类型的使用是一个常见的考点,其中对 key 类型的合法性 是一道常被提及的基础却很容易被忽视的问题。本文将带你深入理解 Golang 中…...

《用户共鸣指数(E)驱动品牌大模型种草:如何抢占大模型搜索结果情感高地》
在注意力分散、内容高度同质化的时代,情感连接已成为品牌破圈的关键通道。我们在服务大量品牌客户的过程中发现,消费者对内容的“有感”程度,正日益成为影响品牌传播效率与转化率的核心变量。在生成式AI驱动的内容生成与推荐环境中࿰…...

ETLCloud可能遇到的问题有哪些?常见坑位解析
数据集成平台ETLCloud,主要用于支持数据的抽取(Extract)、转换(Transform)和加载(Load)过程。提供了一个简洁直观的界面,以便用户可以在不同的数据源之间轻松地进行数据迁移和转换。…...
python如何将word的doc另存为docx
将 DOCX 文件另存为 DOCX 格式(Python 实现) 在 Python 中,你可以使用 python-docx 库来操作 Word 文档。不过需要注意的是,.doc 是旧的 Word 格式,而 .docx 是新的基于 XML 的格式。python-docx 只能处理 .docx 格式…...
在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用
1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...

【Oracle】分区表
个人主页:Guiat 归属专栏:Oracle 文章目录 1. 分区表基础概述1.1 分区表的概念与优势1.2 分区类型概览1.3 分区表的工作原理 2. 范围分区 (RANGE Partitioning)2.1 基础范围分区2.1.1 按日期范围分区2.1.2 按数值范围分区 2.2 间隔分区 (INTERVAL Partit…...

2025季度云服务器排行榜
在全球云服务器市场,各厂商的排名和地位并非一成不变,而是由其独特的优势、战略布局和市场适应性共同决定的。以下是根据2025年市场趋势,对主要云服务器厂商在排行榜中占据重要位置的原因和优势进行深度分析: 一、全球“三巨头”…...
【Go语言基础【13】】函数、闭包、方法
文章目录 零、概述一、函数基础1、函数基础概念2、参数传递机制3、返回值特性3.1. 多返回值3.2. 命名返回值3.3. 错误处理 二、函数类型与高阶函数1. 函数类型定义2. 高阶函数(函数作为参数、返回值) 三、匿名函数与闭包1. 匿名函数(Lambda函…...

Selenium常用函数介绍
目录 一,元素定位 1.1 cssSeector 1.2 xpath 二,操作测试对象 三,窗口 3.1 案例 3.2 窗口切换 3.3 窗口大小 3.4 屏幕截图 3.5 关闭窗口 四,弹窗 五,等待 六,导航 七,文件上传 …...