Android Studio实现登录界面功能

本文实例为大家分享了vue + element ui实现锚点定位的具体代码,供大家参考,具体内容如下

题目

设计一个登录界面。要求:

a) 包含用户名、密码、记住密码、“忘记密码”按钮和“登录”按钮。
b) 单击“忘记密码”按钮弹出提示对话框,对话框内容自拟。

答案

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_login"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
<RelativeLayout
android:id="@+id/login_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:focusable="true"
android:focusableInTouchMode="true"
    >
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/login_edit_pwd"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp">
    <Button
        android:id="@+id/login_btn_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="52dp"
        android:layout_marginRight="50dp"
        android:background="#545bcb"
        android:text="登录"
        android:textColor="#ffffff"
        android:textSize="20sp"/>
    <Button
        android:id="@+id/login_btn_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="260dp"
        android:layout_marginTop="52dp"
        android:background="#e52525"
        android:text="注册"
        android:textColor="#ffffff"
        android:textSize="20sp"/>
</RelativeLayout>

<ImageView
    android:layout_width="300dp"
    android:layout_height="150dp"
    android:id="@+id/logo"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignWithParentIfMissing="false"
    android:background="#ffffff"
    android:src="@drawable/user"/>

<EditText
    android:layout_width="400dp"
    android:layout_height="60dp"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/login_edit_pwd"
    android:drawableLeft="@android:drawable/ic_lock_idle_lock"
    android:hint="请输入您的密码"
    android:layout_below="@+id/login_edit_account"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    />

<EditText
    android:layout_width="400dp"
    android:layout_height="60dp"
    android:inputType="textPersonName"
    android:id="@+id/login_edit_account"
    android:drawableLeft="@android:drawable/ic_menu_myplaces"
    android:hint="请输入您的用户名"
    android:layout_below="@+id/logo"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="20dp"
    />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/login_edit_pwd"
    >

<CheckBox
        android:id="@+id/Login_Remember"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:checked="false"
        android:text="记住密码"
        android:textSize="15sp"/>
    <Button
        android:id="@+id/login_btn_forgetregister"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="0dp"
        android:backgroundTint="#ffffff"
        android:text="忘记密码"
        android:textColor="@color/black"
        android:textSize="15sp"/>

</LinearLayout>
</RelativeLayout>
</RelativeLayout>

MainActivity.java。

package com.example.myapplication;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AlertDialog;
 import androidx.appcompat.app.AppCompatActivity;
 public class MainActivity extends AppCompatActivity{
     @Override
     protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button=(Button)findViewById(R.id.login_btn_forgetregister);
        button.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){new AlertDialog.Builder(MainActivity.this).setTitle("系统提示").setMessage("请输入验证信息进行验证!")
                    .setPositiveButton("确定",new DialogInterface.OnClickListener(){
                        @Override
                        public void onClick(DialogInterface dialog,int which){
                            finish();
                        }
        }).setNegativeButton("返回",new DialogInterface.OnClickListener(){
                        @Override
                        public void onClick(DialogInterface dialog,int which){
                        }

}).show();
        }
        });
        Button button1=(Button)findViewById(R.id.login_btn_login);
        button1.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                new AlertDialog.Builder(MainActivity.this).setTitle("系统提示").setMessage("验证成功!")
        .setNegativeButton("确定",new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog,int which){
        }
        }).show();
        }
        });
        Button button2=(Button)findViewById(R.id.login_btn_register);
        button2.setOnClickListener(new View.OnClickListener(){
            @Override
                    public void onClick(View v){
        new AlertDialog.Builder(MainActivity.this).setTitle("系统提示").setMessage("注册成功!")
        .setNegativeButton("确定",new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog,int which){
        }
        }).show();
        }
        });
   }
}

运行结果

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

(0)

相关推荐

  • Android开发实例之登录界面的实现

    本文要演示的Android开发实例是如何完成一个Android中的miniTwitter登录界面,下面将分步骤讲解怎样实现图中的界面效果,让大家都能轻松的做出美观的登录界面.        miniTwitter登录界面效果图 先贴上最终要完成的效果图:   miniTwitter登录界面的布局分析 首先由界面图分析布局,基本可以分为三个部分,下面分别讲解每个部分. 第一部分是一个带渐变色背景的LinearLayout布局,关于背景渐变色就不再贴代码了,效果如下图所示: 第二部分,红色线区域内,

  • Android QQ登录界面绘制代码

    先看看效果图: 首先过程中碰到的几个问题: 1.对 EditText 进行自定义背景 2.运行时自动 EditText 自动获得焦点 3.在获得焦点时即清空 hint ,而不是输入后清空 4.清空按钮的出现时机(在得到焦点并且有输入内容时) ---  这些问题都有一一解决 --- 以下是代码: 布局 fragment_main(问题2) <!-- android:focusable="true" android:focusableInTouchMode="true&qu

  • Android Studio实现简单的QQ登录界面的示例代码

    一.项目概述 QQ是我们日常生活使用最多的软件之一,包含登录界面和进入后的聊天界面.好友列表界面和空间动态界面等.登录界面的制作比较简单,主要考验布局的使用,是实现QQ项目的第一步.现在APP开发的首要工作都是实现登录页面,所以学会了QQ登录界面对以后的软件开发有着很重要的作用. 二.开发环境 三.详细设计 1.头像设计 首先在layout文件里面选择了RelativeLayout(相对布局)作为整个页面的布局. 在顶端放置了一个ImageView控件,宽度和高度设置的都是70dp,水平居中设置

  • Android实现简洁的APP登录界面

    今天需求要做一个所有app都有的登录界面,正好巩固一下我们之前学的基础布局知识. 先来看下效果图 1.布局的xml文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent&qu

  • Android实现登录界面的注册功能

    本文实例为大家分享了Android登录界面的注册实现代码,供大家参考,具体内容如下 注册一个登录界面在控制台将输入的信息文本选框展示出来 xml界面设计(前面已发) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="h

  • Android属性动画实现炫酷的登录界面

    我们聊聊我们常写的登录界面,这个界面我相信很多人都写过,而且也没什么难度,但是如果要实现比较不一般的效果,那就要花点心思了,先看看项目的效果吧: 我一直都不知道怎么在编辑框连设置图片大小,所以这个图不怎么样适配编辑框了,大家先凑合着看看. 我先讲讲思路,当我们输入完账号跟密码之后,点击登录,那这个输入框就慢慢的消失,在消失后,紧接着就出现这个进度的界面. 思路有了,那我们就开始编码了: 新建一个项目,然后系统生成了一个MainActivity.java文件和activity_main.xml文件

  • Android设计登录界面、找回密码、注册功能

    本文实例为大家分享了Android 登录.找回密码.注册功能的实现代码,供大家参考,具体内容如下 1.数据库的设计 我在数据库中添加了两张表,一张表用来存储用户信息,诸如用户名,密码,手机号等,可任意添加.另一张表用来存储上一个登录用户的账户信息,我是为了方便才另外创建了一张表去存储,而且这张表我设计了它只能存储一条信息,每次的存储都是对上一条记录的覆盖.事实上,我尝试过在存储用户信息的那张表内添加一个标识,用来标记上一次登录的是哪一个帐号,但是这样做的话,每次改变标识都需要遍历整张表,十分的麻

  • Android实现注册登录界面的实例代码

    本文讲述了在linux命令下导出导入.sql文件的方法.分享给大家供大家参考,具体如下: AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="online.geekgalaxy.layoutlearn

  • 功能强大的登录界面Android实现代码

    前言 一个好的应用需要一个有良好的用户体验的登录界面,现如今,许多应用的的登录界面都有着用户名,密码一键删除,用户名,密码为空提示,以及需要输入验证码的功能.看着csdn上的大牛们的文章,心里想着也写一个登录界面学习学习,许多东西都是参考别的文章,综合起来的.废话少说,接下来看看是如何实现的. ps:由于懒得抠图.所以程序的图标很难看. 程序运行时的图示: 首先是布局文件没有什么难度. <RelativeLayout xmlns:android="http://schemas.androi

  • Android登录界面的实现代码分享

    最近由于项目需要,宝宝好久没搞Android啦,又是因为项目需要,现在继续弄Android,哎,说多了都是泪呀,别的不用多说,先搞一个登录界面练练手,登录界面可以说是Android项目中最常用也是最基本的,如果这个都搞不定,那可以直接去跳21世纪楼啦. 废话不多说,先上效果图了,如果大家感觉还不错,请参考实现代码吧. 相信这种渣渣布局对很多人来说太简单啦,直接上布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk

随机推荐