当前位置: 首页 > news >正文

安卓如何书写注册和登录界面

一、如何跳转一个活动

左边的是本活动名称, 右边的是跳转界面活动名称

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,说明来意,付费即可获取工程

相关文章:

安卓如何书写注册和登录界面

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

黄仁勋的AI时代:英伟达GPU革命的狂欢与挑战

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

Linux云计算架构师涨薪班课程内容包含哪些?

第一阶段&#xff1a;Linux云计算运维初级工程师 目标 云计算工程师&#xff0c;Linux运维工程师都必须掌握Linux的基本功&#xff0c;这是一切的根本&#xff0c;必须全部掌握&#xff0c;非常重要&#xff0c;有了这些基础&#xff0c;学习上层业务和云计算等都非常快&#x…...

c语言:自定义类型(枚举、联合体)

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

2024年适合GISer参加的全国性比赛

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

番外篇-用户购物偏好标签BP-推荐算法ALS

引言 推荐系统式信息过载所采用的措施&#xff0c;面对海量的数据信息&#xff0c;从中快速推荐出符合用户特点的物品。 推荐系统是自动化的通过分析用户对历史行为数据&#xff0c;完成用户的个性化建模&#xff0c;从而主动给用户推荐能够满足他们兴趣和需求的软件系统。 数…...

气膜体育馆的防火性能分析—轻空间

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

什么台灯对眼睛好?一文给你分享具体什么台灯对眼睛好!

什么台灯对眼睛好&#xff1f;随着学生们最近陆续返校&#xff0c;家长们和孩子们都忙于开学初的准备工作&#xff0c;而眼睛的健康自然也是他们考虑的一部分。这也是护眼台灯在近年来变得非常普及的原因之一。我自己一直是一个近视的人&#xff0c;而且日常用眼时间也相当长。…...

python-bert模型基础笔记0.1.00

python-bert模型基础笔记0.1.00 bert的适合的场景bert多语言和中文模型bert模型两大类官方建议模型模型中名字的含义标题bert系列模型包含的文件bert系列模型参数参考链接bert的适合的场景 裸跑都非常优秀,句子级别(例如,SST-2)、句子对级别(例如MultiNLI)、单词级别(例…...

STM32G030C8T6:EEPROM读写实验(I2C通信)--M24C64

本专栏记录STM32开发各个功能的详细过程&#xff0c;方便自己后续查看&#xff0c;当然也供正在入门STM32单片机的兄弟们参考&#xff1b; 本小节的目标是&#xff0c;系统主频64 MHZ,采用高速外部晶振&#xff0c;实现PB11,PB10 引脚模拟I2C 时序&#xff0c;对M24C08 的EEPRO…...

opencascade 布尔运算笔记

BRepAlgoAPI_Common 对两个topods求解 没有公共部分也返回结果了 我想要的结果是没有公共部分返回false 在 Open CASCADE 中使用 BRepAlgoAPI_Common 进行布尔操作时&#xff0c;即使两个 TopoDS_Shape 没有公共部分&#xff0c;操作仍会返回一个结果。为了判断两个形状是否确…...

GPT-4o:人工智能新纪元的突破与展望

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…...

标准化、信息化、数字化、智能化、智慧化与数智化

近年来&#xff0c;标准化、信息化、数字化、智能化、智慧化以及数智化等词汇频繁出现&#xff0c;并逐渐成为业界热议的焦点。在国内&#xff0c;以华为、BAT等为代表的领军企业&#xff0c;不断强调“数字化转型”的重要性&#xff0c;并致力于推动其深入实施。与此同时&…...

14-JavaScript中的点操作符与方括号操作符

JavaScript中的点操作符与方括号操作符&#xff1a;简单理解与应用 笔记分享 在JavaScript中&#xff0c;访问对象的属性有两种常见方式&#xff1a;点操作符&#xff08;.&#xff09;和方括号操作符&#xff08;[]&#xff09;。尽管它们在很多情况下可以互换使用&#xff0…...

智慧大屏是如何实现数据可视化的?

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

【JVM精通之路】垃圾回收-三色标记算法

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

Redis缓存(笔记一:缓存介绍和数据库启动)

目录 1、NoSQL数据库简介 2、Redis介绍 3、Redis(win系统、linux系统中操作) 3.1 win版本Redis启动 3.2 linux版本Redis启动 1、NoSQL数据库简介 技术的分类&#xff1a;&#xff08;发展史&#xff09; 1、解决功能性的问题&#xff1a;Java、Jsp、RDBMS、Tomcat、HTML、…...

OrangePi Kunpeng Pro套装测评:开箱与基本功能测试

前言 大家好&#xff0c;我是起个网名真难。非常荣幸受到香橙派的邀请&#xff0c;同时也是第一次做这个事情&#xff0c;很荣幸对香橙派与华为鲲鹏在2024年5月12日联合发布的新品——香橙派Kunpeng Pro开发板进行深入的评测。这款开发板是香橙派与华为鲲鹏合作推出的高性能平…...

RocketMQ教程(二):RocketMQ以及控制台的安装

RocketMQ-Console RocketMQ-Console 是一个针对 Apache RocketMQ 的开源 Web 监控和管理平台。它提供了一个用户友好的界面,通过 Web 浏览器允许用户对 RocketMQ 集群进行管理和监控。这个控制台使得管理和监测 RocketMQ 集群变得更加直观和方便,特别是对于不熟悉命令行操作的…...

电脑记事本怎么恢复之前的内容记录

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

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…...

[2025CVPR]DeepVideo-R1:基于难度感知回归GRPO的视频强化微调框架详解

突破视频大语言模型推理瓶颈,在多个视频基准上实现SOTA性能 一、核心问题与创新亮点 1.1 GRPO在视频任务中的两大挑战 ​安全措施依赖问题​ GRPO使用min和clip函数限制策略更新幅度,导致: 梯度抑制:当新旧策略差异过大时梯度消失收敛困难:策略无法充分优化# 传统GRPO的梯…...

docker详细操作--未完待续

docker介绍 docker官网: Docker&#xff1a;加速容器应用程序开发 harbor官网&#xff1a;Harbor - Harbor 中文 使用docker加速器: Docker镜像极速下载服务 - 毫秒镜像 是什么 Docker 是一种开源的容器化平台&#xff0c;用于将应用程序及其依赖项&#xff08;如库、运行时环…...

day52 ResNet18 CBAM

在深度学习的旅程中&#xff0c;我们不断探索如何提升模型的性能。今天&#xff0c;我将分享我在 ResNet18 模型中插入 CBAM&#xff08;Convolutional Block Attention Module&#xff09;模块&#xff0c;并采用分阶段微调策略的实践过程。通过这个过程&#xff0c;我不仅提升…...

(二)TensorRT-LLM | 模型导出(v0.20.0rc3)

0. 概述 上一节 对安装和使用有个基本介绍。根据这个 issue 的描述&#xff0c;后续 TensorRT-LLM 团队可能更专注于更新和维护 pytorch backend。但 tensorrt backend 作为先前一直开发的工作&#xff0c;其中包含了大量可以学习的地方。本文主要看看它导出模型的部分&#x…...

深度学习习题2

1.如果增加神经网络的宽度&#xff0c;精确度会增加到一个特定阈值后&#xff0c;便开始降低。造成这一现象的可能原因是什么&#xff1f; A、即使增加卷积核的数量&#xff0c;只有少部分的核会被用作预测 B、当卷积核数量增加时&#xff0c;神经网络的预测能力会降低 C、当卷…...

以光量子为例,详解量子获取方式

光量子技术获取量子比特可在室温下进行。该方式有望通过与名为硅光子学&#xff08;silicon photonics&#xff09;的光波导&#xff08;optical waveguide&#xff09;芯片制造技术和光纤等光通信技术相结合来实现量子计算机。量子力学中&#xff0c;光既是波又是粒子。光子本…...

NPOI Excel用OLE对象的形式插入文件附件以及插入图片

static void Main(string[] args) {XlsWithObjData();Console.WriteLine("输出完成"); }static void XlsWithObjData() {// 创建工作簿和单元格,只有HSSFWorkbook,XSSFWorkbook不可以HSSFWorkbook workbook new HSSFWorkbook();HSSFSheet sheet (HSSFSheet)workboo…...

Chrome 浏览器前端与客户端双向通信实战

Chrome 前端&#xff08;即页面 JS / Web UI&#xff09;与客户端&#xff08;C 后端&#xff09;的交互机制&#xff0c;是 Chromium 架构中非常核心的一环。下面我将按常见场景&#xff0c;从通道、流程、技术栈几个角度做一套完整的分析&#xff0c;特别适合你这种在分析和改…...

LOOI机器人的技术实现解析:从手势识别到边缘检测

LOOI机器人作为一款创新的AI硬件产品&#xff0c;通过将智能手机转变为具有情感交互能力的桌面机器人&#xff0c;展示了前沿AI技术与传统硬件设计的完美结合。作为AI与玩具领域的专家&#xff0c;我将全面解析LOOI的技术实现架构&#xff0c;特别是其手势识别、物体识别和环境…...