Android Studio实现登录界面功能
作者:落幕·重逢 发布时间:2023-06-11 20:27:35
标签:Android,Studio,登录界面
本文实例为大家分享了Android Studio实现登录界面的具体代码,供大家参考,具体内容如下
题目
设计一个登录界面。要求:
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();
}
});
}
}
运行结果
来源:https://blog.csdn.net/LOVE_105/article/details/112340934
0
投稿
猜你喜欢
- package com.test; import java.io.FileNotFoundException;&nbs
- 一、Stream流介绍在JDK8时,JAVA新增了lambda表达式,它与 java.io 包里的 InputStream和 OutputS
- 1.官网下载JDK:1.1下载地址:https://www.oracle.com/java/technologies/javase-down
- Dubbo过滤器概述Dubbo中的过滤器和Web应用中的过滤器的概念是一样的,提供了在服务调用前后插入自定义逻辑的途径。过滤器是整个Dubb
- 目录目标功能点准备工作引入 Maven 依赖配置 DAO 数据层创建 JWT 工具类登录LoginFilterLoginSuccessHan
- 定义定义了算法家族,分别封装起来,让他们之间可以相互替换,此模式让算法的变化,不会影响到使用算法的客户。解决的问题在有多种算法相似的情况下,
- 1、conditional注解介绍含义: 基于条件的注解作用: 根据是否满足某一个特定条件来决定是否创建某个特定的bean意义: Sprin
- AspectJ 是通过注解来描述切点与增强的。1 开发环境要求因为要使用注解,所以请确保使用的 Java5.0 及以上版本。引入 Aspec
- 1.基数排序(radixsort)属于“分配式排序”(distributionsort),又称“桶子法”(bucketsort)或binso
- mybatis项目CRUD步骤1.pom.xml引入相应的依赖<?xml version="1.0" encodi
- 官方文档:https://central.sonatype.org/publish/publish-maven/#a-complete-ex
- 实例如下所示:public class MainActivity {private static final String fileName
- 本文实例为大家分享了Android实现图片点击放大的具体代码,供大家参考,具体内容如下在我的项目中,有点击图片banner后放大浏览的功能。
- Mybatis所需要的jar包:需要引用两个jar包,一个是mybatis,另一个是MySQL-connector-Java,如果是mave
- 本文实例讲述了Java循环队列原理与用法。分享给大家供大家参考,具体如下:在正式进行循环队列学习之前,我们先来看看在顺序队列中删除队首元素出
- 本文实例为大家分享了Android实现拼图游戏的具体代码,供大家参考,具体内容如下本人是用 android studio 完成的源码pack
- @SuppressWarnings比较常见,理解和使用起来都很简单。通过源码可以看出,支持在类、属性、方法、参数、构造方法、本地变量上使用。
- 这篇文章主要介绍了Java数组扩容实现方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参
- C语言求三次方根前话说到C语言求根,我们一般会想到用sqrt(x)函数,它的输入值和返回值都是double型,x取整将会导致编译器错误。但是
- 本文实例讲述了C#装饰者模式。分享给大家供大家参考。具体方法如下:using System;using System.Collections