终于介绍到Design包的最后的东西了。

也很简单,一个是TextInputLayout。

TextInputLayout作为一个父容器,包含一个新的EditText,可以给EditText添加意想不到的效果,特别在注册功能开发中,用处非常广泛。

它可以直接提示输入错误,而不至于像以前一样总是点击按钮后才能检测出输入的错误,当有很多输出框的时候更是难以区分。。

并且还可以把hint 默认提示值放到上面去。

项目已经同步至:https://github.com/nanchen2251/CoordinatorLayout  包含了前面的demo代码

实现界面大概是这样的。

当你输入正确后是这样的。

实现代码也很简单。

添加一个监听焦点事件

  @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_text_input);textInput = (TextInputLayout) findViewById(R.id.text_input_layout);textInput.getEditText().addTextChangedListener(this);}@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {}//完成@Overridepublic void afterTextChanged(Editable s) {if(s.length()<6){textInput.setError("密码不能小于6!");textInput.setErrorEnabled(true);}else{textInput.setErrorEnabled(false);}}

  

XML文件中的定义

<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns: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:orientation="vertical"tools:context="com.example.nanchen.designcoodinatordemo.TextInputActivity"><EditTextandroid:layout_width="match_parent"android:hint="输入用户名.."android:layout_height="wrap_content"/><android.support.design.widget.TextInputLayoutandroid:layout_width="match_parent"android:id="@+id/text_input_layout"android:layout_height="wrap_content"><EditTextandroid:layout_width="match_parent"android:hint="输入密码..."android:layout_height="wrap_content"/></android.support.design.widget.TextInputLayout><android.support.design.widget.TextInputEditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="邮箱"/></LinearLayout>

  

然后再来看一下FloatingActionButton。

其实它就是一个可以悬浮的Button,可以把它放在CoordinatorLayout的容器中并重写FloatingActionButton的Behavior可以达到想要的效果。

这里是下拉隐藏。

package com.example.nanchen.designcoodinatordemo;import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.util.AttributeSet;
import android.view.View;/*** 自定义Behavior* Created by 南尘 on 16-7-14.*/
public class MyBehavior extends FloatingActionButton.Behavior {//写了这个构造方法才能在XML文件中直接指定public MyBehavior(Context context, AttributeSet attrs) {super();}@Overridepublic boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) {return true;//返回true代表我们关心这个滚动事件}@Overridepublic void onNestedPreScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dx, int dy, int[] consumed) {super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);if (dy < 0) {//向下滚动
//            ViewCompat.animate(child).scaleX(1).alpha(1).start();child.show();} else {//向上滚动
//            ViewCompat.animate(child).scaleX(0).alpha(0).start();child.hide();}}
}

  FloatingActionButton是有show和hide显示和隐藏方法的。

具体图就不截了,本人做不来gif动图,略显尴尬,不过抽时间一定好好学学!

转载于:https://www.cnblogs.com/liushilin/p/5672361.html

安卓Design包下的TextInputLayout和FloatingActionButton的简单使用相关推荐

  1. 安卓Design包之AppBar和Toolbar的联用

    前面讲了Design包的的CoordinatorLayout和SnackBar的混用,现在继续理解Design包的AppBar; AppBarLayout跟它的名字一样,把容器类的组件全部作为AppB ...

  2. android design包控件,Android Design包之TextInputLayout和TextInputEditText的组合使用【原创】...

    在Android的日常开发中,EditText是个不可或缺的控件之一,作为输入框,用法也没什么太多值得可说的,拿一个简单的登录界面为例,平时差不多是这样的布局: 一般来说是这样,EditText里面的 ...

  3. Mybatis中接口与映射文件一定要同名且放在同一个包下?

    前言: 相信很多接触Mybatis一段时间的开发者,依旧对这个问题可能还存在疑惑,最近很多读者向我提到过,我觉得还是很有必要写篇文章来抒发一番,毕竟我骚啊. 首先,大部分人是认为接口与映射文件一定要同 ...

  4. Design下TextInputLayout结合EditText的简单使用

    今天写的是Design下的TextInputLayout. 稍微介绍一下,一般我们在App上面登录注册页面时,都需要去检测用户输入的内容是否正确,然后给出提醒或错误显示.之前我们都是布局写一大堆代码, ...

  5. 号外 ! 号外 ! V7包下的View都来此参加同学会 , 快来看,快来看...

    考虑到V7包实在大-–既庞大又强大 , 请所有与会的同学到门口来 我们先拍一张全家福: 1 . android.support.v7.widget.Toolbar 2 . android.suppor ...

  6. 带你实现开发者头条APP(四)---首页优化(加入design包)

    一 .前言 上次模仿开发者头条首页实现了一个版本,给345大神,我的产品经理一看,又被鄙视了一把,说还在用老的技术,于是乎这三天把整个design包研究了一遍,然后把首页的代码几乎重写了一遍....顺 ...

  7. 安卓抓包软件_Packet Capture安卓抓包神器介绍及使用教程

    除了干货,其他什么也没有 源码|资源|软件|教程|揭秘 关 注 Packet Capture是一款安卓抓包软件,能用来提取用户操作程序内容,Packet Capture可以捕获网络数据包,并记录它们使 ...

  8. 2-SII--应用本包下文件写入和读取

    零.先说一下我的IO小工具方法: 1.IO读写: IO.png 2.读取InputStream /*** 读取InputStream** @param is 输入流* @return 流转化的字符串* ...

  9. linux手机刷机包制作工具_大神教你五分钟制作安卓ROM包 ROM包修改教程

    之前很多人在网上问:"如何自己制作安卓ROM包?"今天,刷机帮的小编就给大家分享一篇关于安卓ROM包制作以及修改的实用教程,感兴趣的朋友可以一起来看看,当然,老司机就直接略过. 制 ...

最新文章

  1. AppBaseJs 类库 网上常用的javascript函数及其他js类库写的
  2. 第3周实践项目3 求集合并集
  3. linux IP 命令使用举例
  4. springboot----shiro集成
  5. 【图像处理】——Python+opencv实现二值图像的轮廓边界跟踪以及轮廓面积周长的求解(findcontours函数和contourArea函数)
  6. linux安装mysql和使用c语言操作数据库的方法 c语言连接mysql
  7. Java Collections Framework - Java集合框架List,Map,Set等全面介绍之概要篇
  8. 美国燃油“动脉”被黑客切断,网络安全走向哪里?专访山石网科|拟合
  9. pythonhelloworld实例_Python基于Tkinter的HelloWorld入门实例
  10. mysql5.5.20安装_mysql5.5.20安装文档
  11. Zabbix二次开发_03api列表
  12. python从文件夹中提取指定文件_使用Python实现从各个子文件夹中复制指定文件的方法...
  13. java笔记高级部分
  14. MTK Camera广角左右翻转
  15. opencv学习(十四)之图像颜色通道分离和融合
  16. windows防火墙是干什么的_我可以用windows防火墙做什么
  17. c语言复制粘贴快捷键_大家还知道哪些快捷键方法?如:ctrl+c复制,ctrl+v粘贴
  18. 蓝桥杯试题:Fibonacci数列
  19. Java毕业设计-电影售票管理系统
  20. cad自动填写页码lisp,CAD图纸页码的自动生成-农夫也玩CAD

热门文章

  1. tp3.2.3保持搜索条件的分页
  2. 每天一个linux命令目录
  3. Python的嵌套函数使用和闭包
  4. python【力扣LeetCode算法题库】42-接雨水(双指针法)
  5. Keras【Deep Learning With Python】—Keras基础
  6. linux通信中recv,linux套接字通信之recv中的缓存机制的研究
  7. css画横线箭头_用CSS绘制三角形箭头
  8. python 统计分析apache日志_python切分apache日志文件
  9. debian 开发版 移植_迅雷X Linux版(Debian系通用)
  10. python3.8使用requests_python3.8.1 入门基础学习 之 【 requests 基础学习,python3爬虫必备基础】...