Android开发简易登录界面


title: Android开发第四天
search: 2024-03-22
tags:

  • Android开发

Android开发简易登录界面

文章目录

  • Android开发简易登录界面
    • 一、定义`style`样式
    • 二、完成 `activity_main.xml` 界面具体设计
      • 三、代码简述

背景 :在初学 android 开发的时候,为了尽量熟悉学会基础的 android 开发控件和一些基本语言,写的一个简易登录界面,锻炼代码手感

一、定义style样式

为了简化代码,我们先在 styles.xml 中定义样式,后面遇到相同的代码就能够省下不少代码,类似于前端的组件,写好了组件,可以进行复用

    <style name="tvOne">
        <item name ="android:layout_width">0dp</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:layout_weight">1</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textSize">15dp</item>
    </style>

    <style name="tvTwo">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginLeft">20dp</item>
        <item name="android:textSize">30dp</item>
        <item name="android:textColor">@android:color/white</item>
    </style>

    <style name="vLine" >
        <item name="android:layout_width">1dp</item>
        <item name="android:layout_height">match_parent</item>
        <item name="background">@android:color/white</item>
    </style>

    <style name="hLine" >
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">1dp</item>
        <item name="background">@android:color/holo_red_dark</item>
    </style>

    <style name="etOne">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginLeft"> 30dp</item>
        <item name="background">@null</item>
        <item name="android:textColor">@android:color/white</item>
    </style>

自定义了几个样式,后序我打算用来放在 文本框(TextView)和 分割线 (View)中,以及一个输入框(EditText

打算做成的登录界面框架如下:

在这里插入图片描述

二、完成 activity_main.xml 界面具体设计

代码具体的实现没有什么好说的,就是使用基础的样式设计,完成这个代码的目的也仅仅是为了锻炼一下快捷键,让自己熟悉一下 android 开发的基础语法

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/gg"
        tools:context=".MainActivity">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        <TextView
                android:id="@+id/tv_title"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@color/black"
                android:gravity="center"
                android:text="注册"
                android:textColor="@color/white"
                android:textSize="20sp"
        />

        <LinearLayout android:layout_width="match_parent" android:layout_height="130dp"
                      android:orientation="horizontal">

            <TextView
                    style="@style/tvOne"
                    android:drawableTop="@drawable/ic_launcher_foreground"
                    android:text="用QQ注册"/>

            <View style="@style/vLine"/>

            <TextView style="@style/tvOne"
                      android:drawableTop="@drawable/ic_launcher_foreground"
                      android:text="用微信注册"/>

        </LinearLayout>

        <View style="@style/hLine"/>

        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                android:padding="15dp">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:src="@mipmap/background"/>

            <TextView android:layout_width="wrap_content" android:layout_height="30dp"
                      android:layout_marginLeft="15dp"
                      android:text="请使用电子邮箱注册"
                      android:textColor="@color/white"
                      android:textSize="20dp"/>
        </LinearLayout>

        <View style="@style/hLine"/>

        <LinearLayout android:gravity="center"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:padding="15dp">
            <TextView style="@style/tvTwo"
                      android:text="名字"/>

            <EditText
                    android:id="@+id/et_name"
                    android:minHeight="48dp"
                    style="@style/etOne" android:hint="YourName"/>
        </LinearLayout>

        <View style="@style/hLine"/>

        <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
                      android:gravity="center"
                      android:orientation="horizontal"
                      android:padding="15dp">

            <TextView style="@style/tvTwo"
                      android:text="邮箱"/>

            <EditText android:id="@+id/et_email"
                      android:hint="YourEmail"
                      style="@style/etOne" android:minHeight="48dp"/>

        </LinearLayout>

        <View style="@style/hLine"/>

        <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:padding="15dp">
            <TextView style="@style/tvTwo"
                      android:text="密码"/>

            <EditText android:id="@+id/et_password"
                      style="@style/etOne"
                      android:minHeight="48dp"
                      android:hint="YourPassword"
                      android:inputType="textPassword"/>
        </LinearLayout>

        <View style="@style/hLine"/>

        <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
                      android:orientation="horizontal"
                      android:padding="15dp">

            <TextView style="@style/tvTwo"
                      android:layout_gravity="center"
                      android:text="性别"/>

            <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content"
                        android:id="@+id/rg_sex"
                        android:layout_marginLeft="50dp"
                        android:orientation="horizontal">
                <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content"
                             android:id="@+id/rb_boy"
                             android:text=""
                             android:textColor="@color/material_on_primary_emphasis_high_type"
                             android:textSize="30sp"/>
                <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content"
                             android:id="@+id/rb_girl"
                             android:text=""
                             android:layout_marginLeft="30dp"
                             android:textColor="@color/material_on_primary_emphasis_high_type"
                             android:textSize="30dp"/>
            </RadioGroup>

        </LinearLayout>

        <View style="@style/hLine"/>

        <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
                      android:orientation="vertical"
                      android:padding="15dp">

            <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
                      android:text="请选择你的兴趣和爱好"
                      android:textColor="@color/white"
                      android:textSize="20dp"
                      android:layout_marginLeft="20dp"
                      android:textStyle="bold"/>

            <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
                          android:orientation="horizontal">

                <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content"
                          android:id="@+id/cb_sing"
                          android:text="唱歌"
                          android:layout_marginLeft="10dp"
                          android:textColor="@color/white"
                          android:textSize="20dp"/>

                <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content"
                          android:id="@+id/cb_dance"
                          android:text="跳舞"
                          android:layout_marginLeft="10dp"
                          android:textColor="@color/white"
                          android:textSize="20dp"/>

                <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content"
                          android:id="@+id/cb_read"
                          android:text="阅读"
                          android:layout_marginLeft="10dp"
                          android:textColor="@color/white"
                          android:textSize="20dp"/>

                <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content"
                          android:id="@+id/cb_chess"
                          android:text="下棋"
                          android:layout_marginLeft="10dp"
                          android:textColor="@color/white"
                          android:textSize="20dp"/>
                
            </LinearLayout>
            
        </LinearLayout>
        
        <View style="@style/hLine"/>
        
    </LinearLayout>
    
    <View android:layout_width="match_parent" android:layout_height="1dp"
          android:id="@+id/v_line"
          android:layout_above="@+id/btn_submit"
          android:background="@android:color/darker_gray"/>
    
    <Button android:layout_width="match_parent" android:layout_height="50dp"
            android:id="@+id/btn_submit"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:text="提交"
            android:textSize="20dp"
            android:textStyle="bold"/>

</RelativeLayout>

三、代码简述

avtivity_main.xml代码片段是一个用于Android应用的XML布局文件,它定义了MainActivity的用户界面结构。整个布局采用RelativeLayout作为根布局,并且设置了背景为@drawable/gg。以下是代码中各组件的框架解释:

  1. 根布局 RelativeLayout

    • 包含整个屏幕的布局,并设置了宽度和高度为父容器(match_parent),即全屏显示。
    • 背景引用了资源@drawable/gg
  2. 内部第一个LinearLayout

    • 垂直方向排列子视图。
    • 含有以下组件:
      • TextView:标题栏,居中显示文字“注册”。
      • 一个水平排列的LinearLayout,包含两个TextView和一个分割线ViewvLine样式),分别代表两种社交账号登录方式(QQ和微信)。
      • 分割线ViewhLine样式)。
      • 一个包含ImageViewTextViewLinearLayout,提示用户使用电子邮件注册。
      • 更多的分割线和垂直排列的LinearLayouts,分别对应姓名、邮箱、密码的输入框,每个输入框都包括一个标签(TextView)和一个实际输入控件(EditText)。
      • 性别选择部分:一个RadioGroup内含两个RadioButton,分别代表男女选项。
      • 兴趣爱好选择部分:一个TextView提示选择兴趣爱好,紧接着是一个包含四个CheckBoxLinearLayout,用于勾选用户的兴趣(唱歌、跳舞、阅读、下棋)。
      • 最后一个分割线View
  3. 底部元素

    • 一个细线View (v_line),位于提交按钮上方,作为视觉分隔。
    • 一个Button元件,id为btn_submit,位于屏幕底部,带有文字“提交”,用于用户完成表单并发送数据至服务器或执行相应的提交操作。

整体上,这段代码构建了一个注册界面,允许用户通过多种方式进行注册,并提供了填写个人信息如姓名、邮箱、密码、性别以及选择兴趣爱好的功能。最后,用户可以通过点击提交按钮来完成注册流程。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/488674.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

RSTP环路避免实验(思科)

华为设备参考&#xff1a;RSTP环路避免实验&#xff08;华为&#xff09; 一&#xff0c;技术简介 RSTP (Rapid Spanning Tree Protocol) 是从STP发展而来 • RSTP标准版本为IEEE802.1w • RSTP具备STP的所有功能&#xff0c;可以兼容STP运行 • RSTP和STP有所不同 减少了…

新书速览|Django 5企业级Web应用开发实战:视频教学版

掌握Django框架开发技能&#xff0c;实战投票应用系统和内容管理系统 本书内容 《Django 5企业级Web应用开发实战&#xff1a;视频教学版》精选当前简单、实用和流行的Django实例代码&#xff0c;帮助读者学习和掌握Django 5框架及其相关技术栈的开发知识。本书系统全面、内容…

深入解析MySQL的四种打开方式

博主猫头虎的技术世界 &#x1f31f; 欢迎来到猫头虎的博客 — 探索技术的无限可能&#xff01; 专栏链接&#xff1a; &#x1f517; 精选专栏&#xff1a; 《面试题大全》 — 面试准备的宝典&#xff01;《IDEA开发秘籍》 — 提升你的IDEA技能&#xff01;《100天精通鸿蒙》 …

伦敦金与纸黄金有什么区别?怎么选?

伦敦金与纸黄金都是与黄金相关的投资品种&#xff0c;近期黄金市场的上涨吸引了投资者的关注&#xff0c;那投资者想开户入场成为黄金投资者应该选择纸黄金还是伦敦金呢&#xff1f;两者有何区别呢&#xff1f;下面我们就来讨论一下。 伦敦金是一种起源于伦敦的标准化黄金交易合…

2015年认证杯SPSSPRO杯数学建模A题(第一阶段)绳结全过程文档及程序

2015年认证杯SPSSPRO杯数学建模 A题 绳结 原题再现&#xff1a; 给绳索打结是人们在日常生活中常用的技能。对登山、航海、垂钓、野外生存等专门用途&#xff0c;结绳更是必不可少的技能之一。针对不同用途&#xff0c;有多种绳结的编制方法。最简单的绳结&#xff0c;有时称…

Go第三方框架--gin框架(一)

序言 Gin框架作为go语言使用最多的web框架&#xff0c;以其快速的响应速度和对复杂http路由配置的支持受到程序员和媛们的喜爱&#xff0c;几乎统治了web市场。但作为一名合格的程序员&#xff0c;要知其然更要知其所以然&#xff0c;不然八股文背的也没有啥意思。本着这个原则…

【Java程序设计】【C00372】基于(JavaWeb)Springboot的社区网格化管理系统(有论文)

TOC 博主介绍&#xff1a;java高级开发&#xff0c;从事互联网行业六年&#xff0c;已经做了六年的毕业设计程序开发&#xff0c;开发过上千套毕业设计程序&#xff0c;博客中有上百套程序可供参考&#xff0c;欢迎共同交流学习。 项目简介 项目获取 &#x1f345;文末点击卡片…

工业互联网下的增强现实

工业互联网下的增强现实 1、 概述 增强现实&#xff08;Augmented Reality&#xff0c;简称AR&#xff09;&#xff0c;增强现实技术也被称为扩增现实&#xff0c;AR增强现实技术是促使真实世界信息和虚拟世界信息内容之间综合在一起的较新的技术内容&#xff0c;其将原本在现…

Apache SeaTunnel和SeaTunnel Web 安装部署

Apache SeaTunnel和SeaTunnel Web 安装部署 前面我们介绍已经介绍过了Apache SeaTunnel,这里我们看一下SeaTunnel 的安装部署,早期的SeaTunnel 是没有web 页面的,只能在命令行里使用,现在SeaTunnel 已经有了web 端了,这就降低了我们的使用门槛 下载配置 我们可以去下面的…

如何理解TCP/IP协议?

一、是什么 TCP/IP&#xff0c;传输控制协议/网际协议&#xff0c;是指能够在多个不同网络间实现信息传输的协议簇 TCP&#xff08;传输控制协议&#xff09; 一种面向连接的、可靠的、基于字节流的传输层通信协议 IP&#xff08;网际协议&#xff09; 用于封包交换数据网络…

2024年最新阿里云服务器价格表_CPU内存+磁盘+带宽价格

2024年阿里云服务器租用费用&#xff0c;云服务器ECS经济型e实例2核2G、3M固定带宽99元一年&#xff0c;轻量应用服务器2核2G3M带宽轻量服务器一年61元&#xff0c;ECS u1服务器2核4G5M固定带宽199元一年&#xff0c;2核4G4M带宽轻量服务器一年165元12个月&#xff0c;2核4G服务…

YT8531调试记录

总结 还是从设备树&#xff0c;mac驱动&#xff0c;mac驱动对mdio总线的注册&#xff0c;phy驱动 &#xff0c;phy的datasheet&#xff0c;cpu的datasheet 几个方面来看来看 0.确认供电&#xff0c;以及phy的地址(一般会有多个地址&#xff0c;根据相关引脚电平可配置) 1.确…

青年人格测验,管理岗和管培生的招聘测评

青年人格测验是由美国心理学家高夫提出&#xff0c;并逐渐完善的一种性格测试工具。在青年人格测验中&#xff0c;人的人格特质被分为许多个维度&#xff0c;不同的维度&#xff0c;都能对我们健全自身性格&#xff0c;了解自己&#xff0c;起着至关重要的作用。 高夫曾是mmpi…

[NKCTF 2024]web解析

文章目录 my first cms全世界最简单的CTF解法一解法二 my first cms 打开题目在最下面发现是CMS Made Simple&#xff0c;版本为2.2.19 扫一下发现存在后台登陆界面&#xff0c;直接访问 用字典爆破下admin的密码为Admin123 然后直接登录&#xff0c;去漏洞库搜一下其实存在…

武汉凯迪正大—开关柜模拟装置

产品简介 产品包括断路器模拟装置,控制器和控制盒,控制盒包括盒体,控制按钮和信号装置,控制按钮和信号装置设置于盒体的表面,且均与控制器连接.控制按钮和信号装置集中安装于控制盒的盒体表面上。 由于控制盒上的控制按钮和信号装置集中安装,使开关柜模拟实验控制装置体积小,…

mysql增量备份与修复

MySQL数据库增量恢复 1.一般恢复 将所有备份的二进制日志内容全部恢复 2.基于位置恢复 数据库在某一时间点可能既有错误的操作也有正确的操作 可以基于精准的位置跳过错误的操作 发生错误节点之前的一个节点&#xff0c;上一次正确操作的位置点停止 3.基于时间点恢复 跳过…

[自动化测试]博客系统测试用报告

目录 (一) 项目介绍 (二) 测试计划 1. 功能测试 &#xff08;1&#xff09;测试环境 &#xff08;2&#xff09;测试用例 &#xff08;3&#xff09;部分的功能测试 2. 自动化测试 项目介绍 项目整体基于 HTTP 协议&#xff0c;前端使用 HTMLCSSJS 构建页面整体布局&#x…

【Unity3D小功能】Unity3D中实现点击‘文字’出现‘UI面板’

推荐阅读 CSDN主页GitHub开源地址Unity3D插件分享简书地址QQ群&#xff1a;398291828 大家好&#xff0c;我是佛系工程师☆恬静的小魔龙☆&#xff0c;不定时更新Unity开发技巧&#xff0c;觉得有用记得一键三连哦。 一、前言 宠粉博主又来了&#xff0c;今天有粉丝问我如何实…

如何在VS Code上搭建 C/C++开发环境

顾得泉&#xff1a;个人主页 个人专栏&#xff1a;《Linux操作系统》 《C从入门到精通》 《LeedCode刷题》 键盘敲烂&#xff0c;年薪百万&#xff01; 一、什么是VScode VScode&#xff08;Visual Studio Code&#xff09;是一款由微软开发的免费开源的轻量级代码编辑器。它…

AI垃圾装满溢出识别摄像机

AI垃圾装满溢出识别摄像机是一种基于人工智能技术的创新设备&#xff0c;旨在实时监测公共场所垃圾箱的装填情况&#xff0c;及时警示相关部门进行清理或更换&#xff0c;提高城市管理效率&#xff0c;改善城市环境质量。这种AI垃圾装满溢出识别摄像机通过搭载先进的图像识别和…