android studio 做登陆界面
先来一个最简单的 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"> <EditText
android:id="@+id/edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" /> <EditText
android:id="@+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" /> <Button
android:id="@+id/button_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Log in" /> </LinearLayout>
这个没有背景什么的,特别简陋。
接着又写了一个稍微花哨点的。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"> <ImageView
android:id="@+id/image_logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="72dp"
android:src="@drawable/logo" /> <EditText
android:id="@+id/edit_text_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/image_logo"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="48dp"
android:background="@drawable/edit_text_bg"
android:drawableLeft="@drawable/ic_user"
android:drawablePadding="16dp"
android:hint="Username"
android:padding="16dp"
android:textColor="@color/dark_gray"
android:textColorHint="@color/light_gray" /> <EditText
android:id="@+id/edit_text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/edit_text_username"
android:layout_marginHorizontal="24dp"
android:background="@drawable/edit_text_bg"
android:drawableLeft="@drawable/ic_password"
android:drawablePadding="16dp"
android:hint="Password"
android:inputType="textPassword"
android:padding="16dp"
android:textColor="@color/dark_gray"
android:textColorHint="@color/light_gray" /> <Button
android:id="@+id/button_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/edit_text_password"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="36dp"
android:background="@drawable/button_bg"
android:text="Log in"
android:textColor="@color/white" /> </RelativeLayout>
附加 edit_text_bg.xml,button_bg.xml,colors.xml,background.xml、edit_text_bg.xml、button_bg.xml
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="red">#FF0000</color>
<color name="dark_gray">#333333</color>
<color name="light_gray">#CCCCCC</color>
<color name="button_bg_normal">#2196F3</color>
<color name="button_bg_pressed">#1976D2</color>
</resources>
colors.xml文件应该放在values文件夹中
background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> <gradient
android:startColor="#FFC107"
android:endColor="#FF9800"
android:type="linear" /> </shape>
edit_text_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> <solid android:color="@color/white" /> <corners android:radius="8dp" /> <stroke
android:width="1dp"
android:color="@color/light_gray" /> </shape>
button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient
android:startColor="@color/button_bg_pressed"
android:endColor="@color/button_bg_normal"
android:angle="270" /> <corners android:radius="8dp" /> <padding
android:left="16dp"
android:top="12dp"
android:right="16dp"
android:bottom="12dp" />
</shape>
</item> <item>
<shape>
<gradient
android:startColor="@color/button_bg_normal"
android:endColor="@color/button_bg_normal"
android:angle="270" /> <corners android:radius="8dp" /> <padding
android:left="16dp"
android:top="12dp"
android:right="16dp"
android:bottom="12dp" />
</shape>
</item>
</selector>
background.xml,edit_text_bg.xml和button_bg.xml文件应该放在drawable文件夹中
最后由三张图片,分别是logo,用户图标,密码图标。
logo.png
在drawable文件夹中放置一张适当大小的Logo图片即可。
ic_user.png
在drawable文件夹中放置一张适当大小的用户图标图片即可。
ic_password.png
在drawable文件夹中放置一张适当大小的密码图标图片即可。
最后想让账号只能使用11位手机号,只需替代部分EditText
<EditText
android:id="@+id/et_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/phone_number"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:textColor="@color/black"
android:textColorHint="@color/gray"
android:textSize="16sp" />
最后提供用户图标和密码图标,logo就随便了,别忘了修改文件名


android studio 做登陆界面的更多相关文章
- android studio 新建项目 界面一直停在 【“building ‘ 项目名’ gradle project info”】
zhezhelin android studio 新建项目 界面一直停在 [“building ‘ 项目名’ gradle project info”] 安装了android studio 之后,按照 ...
- 只能用Android studio做平台移植了! 在Windows10下, 开发Android。
安装好IDE后, 会一直显示同步失败, 看看如下步骤: 需要注意的是: -> 安装NDK 自带的NDK版本有问题 自己去下一个15版本的 -> 按照系统提示一步一步安装其他 ...
- android studio 新建项目 界面一直停在 【“building ‘ 项目名’ gradle project info”】
安装了android studio 之后,按照上文所述的那篇博文下载安装gradle,配置环境变量, 启动android studio,新建项目,发现还是新建不了,界面一直停在 ["buil ...
- Android——用对话框做登陆界面(自定义对话框AlertDialog,多线程,进度条ProgressDialog,ListView,GridView,SharedPreferences存,读数据,存取文本,assets文件)
效果: 1.点击图标进入页面二 2.页面2图片暂停显示5秒进入页面三 3.点击页面三登陆按钮,打开登陆对话框,输入密码进入页面四 点击下载按钮,显示水平进度条 点击保存和获取用户名和密码 进入页面六 ...
- Android Studio实现登陆注册功能之手机号验证
我们平常写的登陆注册功能,就是很普通的注册一个账号,设置密码,然后登录.这次,想写一个与之前稍微不一样的登陆注册界面,于是想到了手机号验证的方式. 现在我们市面上出现的很多app,都是采用的手机号注册 ...
- Android studio 简易登录界面
•参考资料 [1]:视频资源 [2]:Android TextView设置图标,调整图标大小 •效果展示图 •前置知识 TextView EditText Button 以及按压效果,点击事件 •出现 ...
- Android零基础入门第12节:熟悉Android Studio界面,开始装逼卖萌
原文:Android零基础入门第12节:熟悉Android Studio界面,开始装逼卖萌 通过前两期的学习,我们可以正确搭建好Android Studio的开发环境,也创建了HelloWorld工程 ...
- 如何通过Android Studio发布library到jCenter和Maven Central
http://www.jianshu.com/p/3c63ae866e52# 在Android Studio里,如果你想引入任何library到自己的项目中,只需要很简单的在module的build. ...
- Android零基础入门第13节:Android Studio配置优化,打造开发利器
原文:Android零基础入门第13节:Android Studio配置优化,打造开发利器 是不是很多同学已经有烦恼出现了?电脑配置已经很高了,但是每次运行Android程序的时候就很卡,而且每次安装 ...
- 导入Eclipse工程 到 Android Studio
一.从Eclipse导入工程到Android Studio 根据官方的介绍,Android Studio可以兼容Eclipse的现有工程,但需要做一些操作: 首先升级ADT到最新版本,目前为版本号为2 ...
随机推荐
- 更改docker里mysql的字符编码
进入容器: docker exec -it 容器id/容器名称 bash cp时容器中的目录写法 容器名称/容器id:容器目录 退出容器使用exit 1 首先去mysql容器中寻找mysq ...
- 字符串替换Replace仅替换第一个匹配项
C#里面的String.Replace(string,string)方法替换的时候是替换所有的匹配项,但是有时候我们会遇到这样的需求,就是只替换第一个匹配项. 我这里自己写另一个方法来实现这个功能,求 ...
- revit转tileset 3dmax转tileset cesium展示
使用revit软件导出fbx模型: 使用glTFExport导出gltf模型,导出的gltf模型具有属性.但是此处导出gltf模型,不是为了在cesium中加载该gltf模型,主要目的是获取组件属性信 ...
- springBoot的全局异常处理
GlobalException.java package com.bank.util; import com.bank.exception.ContentEmpyException; import c ...
- Apache Ranger系列六:Submarine Spark Security Plugin安装(0.6.0版本)
参考 https://submarine.apache.org/zh-cn/docs/0.6.0/userDocs/submarine-security/spark-security/ 从ranger ...
- 本地插件文件导入cordova 项目中
cordova plugin add F:\ucc\android\cordova-plugin-datepicker add 后面是插件文件的本地地址
- Leecode 141.环形链表(Java 快慢指针)
想法: 1:遍历链表,每次判断节点是否被访问过.(哈希表) 2:快慢指针(看题解之后) 两个指针pq都在head头指针开始(初始化): 快指针每次走两步,慢指针每次走一步,如果 ...
- 记一个线上问题,selectById查询id出现两条数据问题
查询selectById(),查询1529665444035670017(Long)结果出现两条数据: id:1529665444035670017,和id:1529665444035670018 调 ...
- 使用Wireshark查看HTTPS中TLS握手过程
通过使用Wireshark抓包分析TLS握手的过程,可以更容易理解和验证TLS协议,本文将先介绍Wireshark解密HTTPS流量的方法,然后分别验证TLS握手过程和TLS会话恢复的过程. 一.使用 ...
- Java学习小总结它又又又又来啦!
又到了输出总结的时候啦,话不多说,直接开始输出! 一.final final修饰符的主要作用就是强调它所修饰的板块的"最后"性: 若是修饰成员方法:那么成员方法不可以再被重写: 若 ...