Android Studio实现登录界面功能
作者:落幕·重逢 时间:2023-06-11 20:27:35
本文实例为大家分享了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
标签:Android,Studio,登录界面
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C# ping网络IP 实现网络状态检测的方法
2023-01-11 14:31:05
C# 利用PdfSharp生成Pdf文件的示例
2022-01-18 17:31:30
![](https://img.aspxhome.com/file/2023/0/119530_0s.png)
C#实现状态栏提示信息功能的示例
2022-01-05 12:36:57
![](https://img.aspxhome.com/file/2023/5/106415_0s.jpg)
Java枚举详解及使用实例(涵盖了所有典型用法)
2023-06-29 23:17:55
Android 自定义view和属性动画实现充电进度条效果
2023-08-24 00:18:37
![](https://img.aspxhome.com/file/2023/4/96014_0s.gif)
Java利用钉钉机器人实现发送群消息
2021-06-28 23:37:33
![](https://img.aspxhome.com/file/2023/8/70968_0s.png)
java实现爬取知乎用户基本信息
2023-11-26 03:45:18
![](https://img.aspxhome.com/file/2023/0/116220_0s.png)
Android Studio下Flutter环境搭建图文教程
2023-11-06 00:08:03
![](https://img.aspxhome.com/file/2023/5/138895_0s.jpg)
详解Android使GridView横向水平滚动的实现方式
2023-01-04 16:59:19
![](https://img.aspxhome.com/file/2023/1/137251_0s.gif)
Spring中ApplicationContextAware的使用方法详解
2023-12-25 07:01:33
Android异常处理最佳实践
2021-06-15 20:17:12
Android10开发者常见问题(小结)
2023-05-08 10:27:24
C# Random类的正确应用方法
2021-06-25 14:56:17
![](https://img.aspxhome.com/file/2023/0/94620_0s.png)
SpringBoot Bean被加载时进行控制
2022-10-01 14:06:53
![](https://img.aspxhome.com/file/2023/3/74773_0s.png)
C#实现截取验证码图片
2023-08-04 04:22:56
![](https://img.aspxhome.com/file/2023/5/104245_0s.png)
Java中用POI实现将数据导出到Excel
2022-09-22 00:06:09
![](https://img.aspxhome.com/file/2023/3/119793_0s.png)
java实现简单猜拳小游戏
2021-09-01 07:49:46
![](https://img.aspxhome.com/file/2023/3/79223_0s.jpg)
Java中equalsIgnoreCase()方法的使用
2022-07-28 15:13:45
Java超详细讲解抽象类的原理与用法
2022-10-31 20:51:42
![](https://img.aspxhome.com/file/2023/6/80306_0s.png)
Kotlin入门学习教程之可见性修饰符
2022-02-22 15:14:59