当前位置: 首页 > news >正文

Android开发,实现一个简约又好看的登录页

文章目录

    • 1. 编写布局文件
    • 2.设计要点说明
    • 3. 效果图
    • 4. 关于作者其它项目视频教程介绍

1. 编写布局文件

  • 编写activity.login.xml 布局文件
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="200dp"android:background="@drawable/gradient_background5"><androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="wrap_content"app:title="登录"app:titleTextColor="@color/white" /></RelativeLayout><androidx.core.widget.NestedScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginTop="-50dp"><androidx.appcompat.widget.LinearLayoutCompatandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/img_shape_login_bg"android:orientation="vertical"><androidx.appcompat.widget.LinearLayoutCompatandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="30dp"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="欢迎登录雅居名宿"android:textColor="@color/purple_200"android:textSize="24sp"android:textStyle="bold" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:text="继续登录您的账号!"android:textColor="#BDBDBD"android:textSize="13sp" /><androidx.appcompat.widget.LinearLayoutCompatandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginTop="46dp"android:text="用户名"android:textColor="#585858" /><EditTextandroid:id="@+id/et_username"android:layout_width="match_parent"android:layout_height="40dp"android:layout_marginTop="6dp"android:background="@drawable/login_et_bg"android:hint="请输入用户名"android:paddingLeft="10dp"android:paddingRight="10dp"android:textSize="14sp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginTop="16dp"android:text="密码"android:textColor="#585858" /><EditTextandroid:id="@+id/et_password"android:layout_width="match_parent"android:layout_height="40dp"android:layout_marginTop="6dp"android:background="@drawable/login_et_bg"android:hint="请输入密码"android:inputType="textPassword"android:paddingLeft="10dp"android:paddingRight="10dp"android:textSize="14sp" /><CheckBoxandroid:id="@+id/checkbox"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="记住密码" /><TextViewandroid:id="@+id/btn_login"android:layout_width="match_parent"android:layout_height="50dp"android:layout_marginTop="20dp"android:background="@drawable/gradient_background4"android:gravity="center"android:text="登录"android:textColor="#ffffff"android:textSize="16dp" /><androidx.appcompat.widget.LinearLayoutCompatandroid:id="@+id/btn_register"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginTop="20dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="30dp"android:layout_gravity="center"android:gravity="center"android:text="还没有账号?"android:textColor="#747481"android:textSize="13sp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="30dp"android:layout_gravity="center"android:gravity="center"android:text=" 注册"android:textColor="@color/purple_200"android:textSize="13sp" /></androidx.appcompat.widget.LinearLayoutCompat></androidx.appcompat.widget.LinearLayoutCompat></androidx.appcompat.widget.LinearLayoutCompat></androidx.appcompat.widget.LinearLayoutCompat></androidx.core.widget.NestedScrollView></androidx.appcompat.widget.LinearLayoutCompat>
  • 在res/drawable创建顶部渐变背景 gradient_background5.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><gradientandroid:startColor="@color/purple_200"android:endColor="#BBCEE9"android:angle="270"android:type="linear"/></shape>
  • 在res/drawable创建登录按钮背景 gradient_background4.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><gradientandroid:startColor="#0066f5"android:endColor="#A9C0E7"android:angle="45" /><cornersandroid:bottomLeftRadius="10dp"android:topRightRadius="10dp" /></shape>
  • 在res/drawable创建登录区域背景 img_shape_login_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><solid android:color="@color/white"/><cornersandroid:topLeftRadius="15dp"android:topRightRadius="15dp" /></shape>

2.设计要点说明

  1. 父布局使用LinearLayoutCompat线性布局包裹
  2. 自适应小屏幕使用NestedScrollView包裹,在使用NestedScrollView时,特别注意它的子组件只能有且仅有一个
  3. 使用shape来实现背景圆角,渐变等设置

3. 效果图

在这里插入图片描述

4. 关于作者其它项目视频教程介绍

  1. Android新闻资讯app实战:https://www.bilibili.com/video/BV1CA1vYoEad/?vd_source=984bb03f768809c7d33f20179343d8c8
  2. Androidstudio开发购物商城实战:https://www.bilibili.com/video/BV1PjHfeXE8U/?vd_source=984bb03f768809c7d33f20179343d8c8
  3. Android开发备忘录记事本实战:https://www.bilibili.com/video/BV1FJ4m1u76G?vd_source=984bb03f768809c7d33f20179343d8c8&spm_id_from=333.788.videopod.sections
  4. Androidstudio底部导航栏实现:https://www.bilibili.com/video/BV1XB4y1d7et/?spm_id_from=333.337.search-card.all.click&vd_source=984bb03f768809c7d33f20179343d8c8
  5. Android使用TabLayout+ViewPager2实现左右滑动切换:https://www.bilibili.com/video/BV1Mz4y1c7eX/?spm_id_from=333.337.search-card.all.click&vd_source=984bb03f768809c7d33f20179343d8c8

相关文章:

  • 深入理解java线程池
  • [RoarCTF 2019]Easy Calc 详解
  • 空洞/膨胀卷积
  • clangd-vscode配置
  • 网络安全之红队LLM的大模型自动化越狱
  • LinuxAgent开源程序是一款智能运维助手,通过接入 DeepSeek API 实现对 Linux 终端的自然语言控制,帮助用户更高效地进行系统运维工作
  • 遗传算法实现单货架库位优化
  • 在Linux系统中安装Anaconda的完整指南
  • vue3代码规范管理;基于vite和vue3、 eslint、prettier、stylelint、husky规范;git触发eslint校验
  • JavaWeb:vueaxios
  • 光触发RFID:破解物流、电力、资产管理三大领域的“不可能三角”
  • 基于 Python 的实现:居民用电量数据分析与可视化
  • 基于SpringBoot的食物营养分析与推荐网站系统
  • 22.晶振的信号与布局布线处理
  • 安卓基础(泛型)
  • 跨语言哈希一致性:C# 与 Java 的 MD5 之战?
  • 搭建speak yarn集群:从零开始的详细指南
  • C++(初阶)(十三)——继承
  • 【C++11特性】Lambda表达式(匿名函数)
  • 职坐标IT培训破局AI风口新赛道
  • 日本大米价格连续16周上涨,再创最高纪录
  • 传智教育连续3个交易日跌停:去年净利润由盈转亏
  • 利物浦提前四轮英超夺冠,顶级联赛冠军数追平曼联
  • 野猪穿过江苏电视台楼前广场,被抓捕后送往红山森林动物园
  • 读科学发展的壮丽史诗,也读普通人的传奇
  • “一对一讨论诸多事宜”,泽连斯基披露此次特泽会更多细节