IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码

这篇具有很好参考价值的文章主要介绍了IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

开发工具:IDEA 2022.3.2,未连接数据库。验证用的用户名和密码为内置硬编码

演示程序运行效果: 

IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码

 

设计器中的用户登录页面布局:

IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码

 登录验证容错提示如下:

1,用户名不能为空:

IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码

2,密码不能为空:

IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码 

 

3,用户名不存在:

IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码

4,用户密码错误

IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码 

 5,登录验证成功跳转到用户中心:

IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码

源码如下: 

登录页面布局:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    <EditText
            android:id="@+id/editName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="请输入用户名"
            android:drawableLeft="@drawable/baseline_people_24"
            android:drawablePadding="10dp"
            android:paddingLeft="10dp"
            android:singleLine="true"
            android:ems="10"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="88dp"/>
    <EditText
            android:id="@+id/editPass"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="请输入密码"
            android:drawableLeft="@drawable/baseline_fingerprint_24"
            android:drawablePadding="10dp"
            android:paddingLeft="10dp"
            android:singleLine="true"
            android:ems="10"
            app:layout_constraintStart_toStartOf="@+id/editName"
            android:layout_marginTop="16dp"
            app:layout_constraintTop_toBottomOf="@+id/editName"
            app:layout_constraintEnd_toEndOf="@+id/editName"
            app:layout_constraintHorizontal_bias="0.0"
            android:password="true"/>

    <Button
            android:id="@+id/btnLogin"
            android:text="登录"
            android:onClick="btnLoginClick"
            android:layout_width="100dp"
            android:layout_height="47dp"
            tools:ignore="MissingConstraints"
            app:layout_constraintEnd_toStartOf="@+id/guideline21"
            android:layout_marginRight="8dp"
            android:layout_marginEnd="8dp"
            app:layout_constraintTop_toTopOf="@+id/guideline22"/>
    <Button
            android:id="@+id/btnReg"
            android:text="注册"
            android:onClick="btnRegClick"
            android:layout_width="100dp"
            android:layout_height="47dp"
            tools:ignore="MissingConstraints"
            app:layout_constraintStart_toStartOf="@+id/guideline21"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            app:layout_constraintTop_toTopOf="@+id/guideline22"/>
    <androidx.constraintlayout.widget.Guideline android:layout_width="wrap_content" android:layout_height="wrap_content"
                                                android:id="@+id/guideline21"
                                                android:orientation="vertical"
                                                app:layout_constraintGuide_percent="0.5"/>
    <androidx.constraintlayout.widget.Guideline android:layout_width="wrap_content" android:layout_height="wrap_content"
                                                android:id="@+id/guideline22" app:layout_constraintGuide_begin="216dp"
                                                android:orientation="horizontal"/>


</androidx.constraintlayout.widget.ConstraintLayout>

登录成功页面布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".UserCenter">

    <TextView
            android:id="@+id/textUserInfo"
            android:layout_width="248dp"
            android:layout_height="73dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginTop="160dp"
            android:layout_marginLeft="96dp"
            android:layout_marginStart="96dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>

登录页面java代码:

package com.example.Login;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private static final String TAG="LOG";
    static String UserName="crystal";
    static String Password="abc456";

    //btnLogin点击事件
    public  void btnLoginClick(View v) {
        Log.e(TAG,"onClick");
        EditText etUser = findViewById(R.id.editName);
        String strUser = etUser.getText().toString().trim();
        EditText edtPass = findViewById(R.id.editPass);
        String strPass = edtPass.getText().toString().trim();

        if (strUser.equals(""))  {
            Toast.makeText(MainActivity.this, "用户名不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (strPass.equals(""))  {
            Toast.makeText(MainActivity.this, "密码不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        if (!strUser.equals(UserName))  {
            Toast.makeText(MainActivity.this, "用户名不存在", Toast.LENGTH_SHORT).show();
            return;
        }

        if (!strPass.equals(Password))  {
            Toast.makeText(MainActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
            return;
        }

        //页面跳转并传参
        Intent intent =new Intent(MainActivity.this, UserCenter.class);
        intent.putExtra("name",strUser);
        intent.putExtra("password",strPass);
        startActivity(intent);

/*
        //验证成功创建一个弹出对话框
        new  AlertDialog.Builder(MainActivity.this)
                .setTitle("提示信息")
                .setMessage("您刚刚点击了登录按钮\n"+"您输入的用户名为:"+strUser+"  密码为:"+strPass)
                .setPositiveButton("确定",null)
                .show();
*/

    }



    //btnReg点击事件Toast消息框的应用
    public void btnRegClick(View v) {
        //创建一个弹出对话框
        Toast.makeText(MainActivity.this,"您刚刚点击了注册按钮", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

登录成功用户中心java代码:

package com.example.Login;

import android.content.Intent;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class UserCenter extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_center);

        //更改页面标题
        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle("用户中心");

        TextView info=findViewById(R.id.textUserInfo);
        Intent intent=getIntent();
        String name=intent.getStringExtra("name");
        String password=intent.getStringExtra("password");
        info.setText("用户:"+name+" 登录成功! ["+name+":"+password+"]");

    }
}

有兴趣的朋友,可以复制代码进行测试,再添加上注册,注销退出功能进行练习巩固.文章来源地址https://www.toymoban.com/news/detail-505534.html

到了这里,关于IDEA Android用户登录页面、登录验证、页面跳转演示示例全部源码的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Android学习(一)--用户登录注册界面(界面跳转+背景音乐)

    目录 1.功能要求 2.功能实现流程图 3.功能演示 4.界面与功能  4.1登录界面 4.1.1界面展示 4.1.2登录界面功能简介 4.1.3界面代码 4.1.4登录按钮点击事件 4.1.5退出按钮点击事件  4.1.6背景音乐点击事件 4.1.7记住密码 5.Java源码 (1)三个界面布局,体现文本框、编辑框、单选按钮、复

    2024年02月05日
    浏览(39)
  • 使用javaweb实现登录注册页面,并且对功能和业务进行分层 用户登录成功跳转到主页并展示数据库的商品的信息

    一、Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp负责数据显示,javabean负责封装数据。 Servlet+JSP+JavaBean模式程序各个模块之间层次清晰,web开发推荐采用此种模式。 这里以一个最常用的用户登录

    2024年02月03日
    浏览(44)
  • android 12版本文件操作需要的权限,需要跳转设置页面,提醒用户手动设置

    安卓12版本的,API31,在对文件file操作时,除了申请 这个是在API30以上都需要的,否则就会报找不到文件的错误  跳转设置项,用户手动打开当前APP的文件操作权限

    2024年02月12日
    浏览(50)
  • Selenium登录页面点击登录页面没有跳转问题(click()失效)

    对于一般的登录界面的登录按钮用xpath定位元素再点击就可以进入页面,但是如果登录不是一个按钮而是一张图片,这时我们该怎么定位并登录成功呢? 比如下面这个登录,并不是按钮而是一个div,div里面放了图片 一开始我用了xpath定位,但是结果就是不报错也没有跳转到登录

    2024年02月08日
    浏览(35)
  • 前端页面跳转的3种方法(HTML示例)

    一、onclick跳转 1. 设置window的location.href属性 2. 调用window的open方法 二、a标签跳转

    2024年02月11日
    浏览(38)
  • pyQt界面制作(登录+跳转页面)

    首先打开Qt-D esigner,选择Widget,它和Main Window的区别在于:Main Window有工具栏菜单栏状态栏等,而Widget就适合做个简单的登录界面。如下图:   首先如下列图,在这里可以设置标题为登录,然后插入一个logo图片,也可以给字体标题设置大小样式等。 接下来输入框都是用Line Edit,

    2024年01月23日
    浏览(34)
  • Qt登录注册页面间跳转

    登录界面 注册界面 实现效果 QQ录屏20220917202345 在登录的类中定义一个私有的注册类成员 右键实现跳转的按钮 选择槽函数 槽函数中实现隐藏登录界面显示注册界面 使用connect函数将信号和槽连接 到这里已经实现了登录界面到注册界面的跳转 在登录界面在定义一个接收信号的

    2024年02月11日
    浏览(35)
  • js做简单的登录页面以及附加条件,登录成功后跳转

    新手第一次上传,还不会介绍,很简单,能看懂不难的   成功后跳转页面代码就更简单了  

    2024年02月11日
    浏览(35)
  • Spring Security登录后一直跳转登录页面原因分析

    引发错误的SpringSecurity配置如下: 测试授权码模式,访问地址:http://localhost:9949/oauth/authorize?client_id=edenresponse_type=codescope=serverredirect_uri=http://www.baidu.com。被Security拦截后,重定向到登录页面。输入正确的用户名和密码,仍然回到登录页面,陷入死循环... 先放一张流程图,待会

    2024年02月11日
    浏览(34)
  • 43、基于 springboot 自动配置的 spring mvc 错误处理,就是演示项目报错后,跳转到自定义的错误页面

    Spring MVC 的错误处理:基于 SpringBoot 自动配置之后的 Spring MVC 错误处理。 就是访问方法时出错,然后弄个自定义的错误页面进行显示。 方式一: 基于Spring Boot自动配置的错误处理方式,只要通过属性文件即可配置错误处理行为。 提供自定义的错误页面即可。 方式二: 使用

    2024年02月10日
    浏览(42)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包