广告
返回顶部
首页 > 资讯 > 移动开发 >Android实现登录注册页面(上)
  • 190
分享到

Android实现登录注册页面(上)

2024-04-02 19:04:59 190人浏览 泡泡鱼
摘要

简单的Android开发登录注册,这个是没有连数据库的。 首先,新建项目,新建一个登录页面LoginActivity和注册页面ReGISterActivity。 下面是登录页面的代码

简单的Android开发登录注册,这个是没有连数据库的。

首先,新建项目,新建一个登录页面LoginActivity和注册页面ReGISterActivity。

下面是登录页面的代码: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"
    android:orientation="vertical"
    tools:context=".LoginActivity">
    <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="20dp"
        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:hint="请输入用户名或手机号"
            style="@style/MyEditStyle"
            android:layout_marginLeft="10dp"
            android:inputType="text"></EditText>
    </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="20dp"
        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:hint="请输入密码"
            style="@style/MyEditStyle"
            android:layout_marginLeft="10dp"
            android:inputType="numberPassword"></EditText>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        >
        <CheckBox
            android:id="@+id/cb_remember"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="记住密码"></CheckBox>
    </LinearLayout>
    <Button
        android:id="@+id/btn_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        style="@style/MyBtnStyle"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"></Button>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:text="还没有账号?"
        android:layout_gravity="right"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:onClick="toRegister"
        ></TextView>
 
</LinearLayout>

效果如图:

下面是注册页面的代码:activity_register.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=".RegisterActivity"
    android:orientation="vertical">
 
 
    <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="20dp"
        android:gravity="center_vertical">
 
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账&#12288;&#12288;号:"
            android:textSize="25sp" />
 
        <EditText
            android:id="@+id/et_account"
            android:layout_width="match_parent"
            android:hint="请输入用户名或手机号"
            style="@style/MyEditStyle"
            android:layout_marginLeft="10dp"
            android:inputType="text"></EditText>
    </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="20dp"
        android:gravity="center_vertical">
 
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密&#12288;&#12288;码:"
            android:textSize="25sp" />
 
        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:hint="请输入密码"
            style="@style/MyEditStyle"
            android:layout_marginLeft="10dp"
            android:inputType="numberPassword"></EditText>
    </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="20dp"
        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:hint="请再次输入密码"
            style="@style/MyEditStyle"
            android:layout_marginLeft="10dp"
            android:inputType="numberPassword"></EditText>
    </LinearLayout>
 
    <Button
        android:id="@+id/btn_register"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="注册"
        style="@style/MyBtnStyle"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"></Button>
 
    <CheckBox
        android:id="@+id/cb_agree"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:text="还没有账号?"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"></CheckBox>
 
</LinearLayout>

效果如图:

最后,在LoginActivity.java中,加入一串代码:getSupportActionBar().setTitle("登录");

在RegisterActivity.java中,加入一串代码:getSupportActionBar().setTitle("注册");

public class LoginActivity extends AppCompatActivity {
 
    public static final int REQUEST_CODE_REGISTER = 1;
    private static final String TAG="tag";
    private Button btnLogin;
    private EditText etAccount,etPassword;
    private CheckBox cbRemember;
    private String userName="a";
    private String pass="123";
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        getSupportActionBar().setTitle("登录");
     }
}

上面的代码是LoginActivity.java中的代码,其实要添加的只有一句,其他都写出来是为了让读者能看懂,具体写在哪里。这段代码的作用是: 使标题栏那边显示的文字是登录/注册,而不是一串默认的英文

下面两张图片,左边是未添加代码的效果,右边是添加代码后的效果

写到这里,页面整体布局大致完成了,下面,你们需要添加部分细节,来使得颜色和样式跟我一致。我在上面的xml文件代码中,有下面这个代码:

style="@style/MyEditStyle"和style="@style/MyBtnStyle"

你们在前面写的时候,可能会报错,很正常,因为这是引用控件样式的代码,你们需要设置一下这个样式,然后引用,就不会报错啦。

这是设置EditText和Button控件的样式,首先新建style.xml文件。在values中右键,New--Values Resource File,文件名为style。在style.xml文件中,写如下代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 
    <style name="MyBtnStyle">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">25sp</item>
        <item name="android:background">@drawable/btn_bg_selector</item>
        <item name="android:layout_marginTop">20dp</item>
        <item name="android:layout_marginRight">20dp</item>
        <item name="android:layout_marginLeft">20dp</item>
    </style>
 
    <style name="MyEditStyle">
        <item name="android:textSize">18sp</item>
        <item name="android:background">@drawable/edit_text_bg</item>
        <item name="android:paddingLeft">10dp</item>
        <item name="android:layout_height">50dp</item>
    </style>
 
</resources>

这里面又引用了样式,是设置输入框的边框和按钮的背景颜色。继续下面的步骤:drawable右键--New--Drawable Resource File,文件名为:btn_bg_selector,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/colorPrimary"></item>
    <item android:state_pressed="false" android:drawable="@color/colorPrimaryDark"></item>
 
</selector>

drawable右键--New--Drawable Resource File,文件名为:edit_text_bg,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
 
    <stroke android:width="2dp" android:color="@color/colorPrimary"></stroke>
    <corners android:radius="10dp"></corners>
 
</shape>

最后,再调整一下导航栏和标题栏的颜色,就OK啦

colors.xml文件中,添加绿色这个颜色,如下代码,

<color name="colorPrimary">@color/green_500</color>
    <color name="colorPrimaryDark">@color/green_700</color>
    <color name="colorAccent">#E64A19</color>
 
    <color name="green_200">#A5D6A7</color>
    <color name="green_500">#4CAF50</color>
<color name="green_700">#4CAF50</color>

themes.xml文件中,只需要修改前两个item的内容,其他代码是为了你们参照一下位置,别改错了。代码如下:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.TraditionalCulture" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryVariant">@color/colorPrimaryDark</item>
        <item name="colorOnPrimary">@color/white</item>
        <item name="colorAccent">@color/colorAccent</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetapi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
</resources>

到这里,你的登录注册页面就完成啦!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: Android实现登录注册页面(上)

本文链接: https://www.lsjlt.com/news/147063.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android实现登录注册页面(上)
    简单的Android开发登录注册,这个是没有连数据库的。 首先,新建项目,新建一个登录页面LoginActivity和注册页面RegisterActivity。 下面是登录页面的代码...
    99+
    2022-11-13
  • Android实现登录注册页面(下)
    前面我们已经完成了登录注册页面的布局,下面我们实现验证登录和记住密码的功能。 我们这里还没用到数据库,所以我们的验证的账号密码,是写死的。 首先进入登录页面,可以从这里跳转到注册页面...
    99+
    2022-11-13
  • Android studio 实现app登录注册页面
    目录 activity_main.xml代码如下 MainActivity.java代码如下 用于高校实现Android studio专业课作业提交,如确实有用,欢迎观众姥爷打赏 该页面实现了注册页面的布局效果,包含用户名,密码,忘记密...
    99+
    2023-10-06
    android-studio adb android android studio
  • node.js实现登录注册页面
    本文实例为大家分享了node.js登录注册页面展示的具体代码,供大家参考,具体内容如下 首先需要新建四个文件 一个服务器js 一个保存数据的txt 一个登陆、一个注册页面html 1、注册页面 <...
    99+
    2022-06-04
    页面 node js
  • javaweb实现注册登录页面
    本文实例为大家分享了javaweb实现注册登录页面的具体代码,供大家参考,具体内容如下 <%@ page language="java" contentType="text/h...
    99+
    2022-11-13
  • Android Studio怎么实现注册页面跳转登录页面
    今天小编给大家分享一下Android Studio怎么实现注册页面跳转登录页面的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了...
    99+
    2023-06-30
  • Java实现登录与注册页面
    用java实现的登录与注册页面,实现了客户端(浏览器)到服务器(Tomcat)再到后端(servlet程序)数据的交互。这里在注册页面加入了验证码验证。 注册的html代码,页面非常...
    99+
    2022-11-13
  • JavaScript实现简易登录注册页面
    本文实例为大家分享了JavaScript实现简易登录注册页面的具体代码,供大家参考,具体内容如下 <!DOCTYPE html> <html>   <h...
    99+
    2022-11-12
  • JavaScript怎么实现注册登录页面
    本篇内容介绍了“JavaScript怎么实现注册登录页面”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! ...
    99+
    2022-10-19
  • Android实现登录注册界面框架
    小项目框架 今天用QQ的时候想到了,不如用android studio 做一个类似于这样的登录软件。当然QQ的实现的功能特别复杂,UI界面也很多,不是单纯的一时新奇就可以做出来的。就...
    99+
    2022-11-12
  • Android实现注册页面
    本文用Android studio制作了简单的手机QQ登录界面,其中界面的布局采用了线性布局、表格布局(不固定布局方法),并给控件绑定监听器,当用户点击登陆按钮时,把用户所填写的注册...
    99+
    2022-11-13
  • Java怎么实现登录与注册页面
    本文小编为大家详细介绍“Java怎么实现登录与注册页面”,内容详细,步骤清晰,细节处理妥当,希望这篇“Java怎么实现登录与注册页面”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。用java实现的登录与注册页面,实...
    99+
    2023-06-30
  • 登录-注册网页实现
    re.php(登录的前端界面) 登录页面 .home{ text-align: center; font-wei...
    99+
    2023-08-31
    数据库 php 前端
  • Android实现登录界面的注册功能
    本文实例为大家分享了Android登录界面的注册实现代码,供大家参考,具体内容如下 注册一个登录界面在控制台将输入的信息文本选框展示出来 xml界面设计(前面已发) <xml ...
    99+
    2022-11-13
  • AndroidStudio实现注册页面跳转登录页面的创建
    本文是用来介绍Android Studio创建注册页面跳转登录页面的界面设计以及跳转功能地实现,完整结构见文章结尾。 用户注册界面 <xml version="1.0" en...
    99+
    2022-11-13
  • 基于Viewpager2实现登录注册引导页面
    本文实例为大家分享了Viewpager2实现登录注册引导页面的具体代码,供大家参考,具体内容如下 介绍 屏幕滑动是两个完整屏幕之间的切换,在设置向导或幻灯片等界面中很常见 实现图(图...
    99+
    2022-11-13
  • JavaScript如何实现简易登录注册页面
    小编给大家分享一下JavaScript如何实现简易登录注册页面,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!具体内容如下<!DOCTYPE htm...
    99+
    2023-06-26
  • android实现注册登录程序
    本文实例为大家分享了android实现注册登录程序的具体代码,供大家参考,具体内容如下 注册页面: user_register.xml: <xml version="1.0" ...
    99+
    2022-11-13
  • Android实现登录注册功能
    本文实例为大家分享了Android实现登录注册功能的具体代码,供大家参考,具体内容如下 运行环境 Android Studio 总体效果图 一、 设计注册页面的布局 二、完成注册...
    99+
    2022-11-13
  • java实现登录注册界面
    本文实例为大家分享了java实现登录注册界面的具体代码,供大家参考,具体内容如下 数据库设计 既然只是一个登录和注册的界面,数据库方面就只设计一个Admin表,表内有三个值。 id...
    99+
    2022-11-13
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作