Material Design之TextInputLayout使用示例

使用TextInputLayout创建一个登陆界面

1.导入支持库

使用TextInputLayout 控件需要导入两个库,一个是appcompat-v7,保证material styles可以向下兼容。另一个是Design Support Library。

在项目的build.gradle文件中,添加下面的依赖(dependencies):

dependencies {
        compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
        compile ‘com.android.support:design:22.2.0‘
        compile ‘com.android.support:appcompat-v7:22.2.0‘
    }

2.使用TextInputLayout

TextInputLayout 控件表现得就像LinearLayout 一样,它是一个容器。TextInputLayout 中只能放一个子元素,和ScrollView有点类似,并且子元素必须是EditText 。

<android .support.design.widget.TextInputLayout
    android:id="@+id/usernameWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <edittext android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:hint="Username"/>

</android .support.design.widget.TextInputLayout>

注意到了么,我在EditText设置一个属性-hint。这个属性大家都很熟悉了,EditText没有输入的时候,hint会显示,当输入第一个字母上去的时候,hint就消失了。这个体验不是太好。 
感谢TextInputLayout,这个马上就不是问题了。当EditText中输入第一个字母要隐藏hint的时候,TextInputLayout中会出现一个悬浮的标签来显示这个hint,还负责一个炫酷的的material 动画。

注:EditText的高度可以固定, TextInputLayout 的高度不要固定,否则TextInputLayout 的setError()的信息可能会无法正常显示

3.app:hintTextAppearance="@style/FloatingStyle"

app:hintTextAppearance=”@style/FloatingStyle” 用于设置floating字体的样式。

<style name="FloatingStyle" parent="@android:style/TextAppearance">
        <item name="android:textColor">#e0ffffff</item>
        <item name="android:textSize">12sp</item>
  </style>

TextInputLayout可以使用setError()方法在输入框下方显示错误信息,用途类似EditText的setError()。同样的,在xml中可以使用app:errorTextAppearance来设置错误信息的字体样式。

参考链接:http://www.mamicode.com/info-detail-965904.html

其他链接:http://www.open-open.com/lib/view/open1433496206666.html

时间: 2024-08-21 09:38:25

Material Design之TextInputLayout使用示例的相关文章

Material Design之TextInputLayout、Snackbar的使用

这两个控件也是Google在2015 I/O大会上公布的Design Library包下的控件,使用比較简单,就放在一起讲了,但有的地方也是须要特别注意一下. TextInputLayout TextInputLayout功能很easy,就是用于用户在EditText中输入时hint的提示和错误的提示. 先来看看效果图吧: 从上图非常明显的看出: 1.当EditText获得焦点时候.TextInputLayout会在左上角默认的生成一个Label用来显示EditText中hint的内容,所以当用

用户登录(Material Design + Data-Binding + MVP架构模式)实现

转载请注明出处: http://www.cnblogs.com/cnwutianhao/p/6772759.html MVP架构模式 大家都不陌生,Google 也给出过相应的参考 Sample, 但是有的人会有疑问为啥 GitHub 上面大神写的 MVP架构模式 和 Google 的不太一样. Google MVP架构模式 Sample 地址 https://github.com/googlesamples/android-architecture/tree/todo-mvp/ 下面我们就仿照

Material Design (二),TextInputLayout的使用

前言 ?一般登录注冊界面都须要EditText这个控件来让用户输入信息,同一时候我们通常会设置一个标签(使用TextView)和EditText的hint属性来提示用户输入的内容,而设计库中高级组件TextInputLayout则专门为EditText设计的.即通过使用TextInputLayout包裹EditText实现当用户開始输入时hint属性值将显示在EditText上面作为一个提示标签,这个过程还带有动画效果,这样就避免了用户输入时输入提示消失的情况,同一时候.还能够更好地向用户提示错

Android Material Design(一)史上最全的材料设计控件大全

主要内容: 本文将要介绍Material design和Support library控件,主要包括TextInputLayout.SwitchCompat.SnackBar.FloatingActionButton.Shadows.Ripples.TabLayout.RecyclerView.Card.NavigationView.BottomSheet.Palette控件. 转载请注明出处,谢谢!! http://blog.csdn.net/johnny901114/article/deta

Material Design Library 使用汇总

我的简书同步发布:Material Design Library 使用汇总 转载请注明出处:[huachao1001的专栏:http://blog.csdn.net/huachao1001] 本文对Material Design Library里面的库类的使用做一个简单的汇总,方便以后能快速查询.快速上手使用.本文包括以下内容: Color Palette Toolbar AppBarLayout CollapsingToolbarLayout CoordinatorLayout DrawerL

Android Material Design 兼容库的使用

Android Material Design 兼容库的使用 mecury 前言:近来学习了Android Material Design 兼容库,为了把这个弄懂,才有了这篇博客,这里先推荐两篇博客:1.Android Material Design 兼容库的使用详解2.Android应用Design Support Library完全使用实例第一篇博客是这个兼容库的详细解析,我参考了里面的许多内容,第二篇是兼容库的大致介绍,如果你能把这两篇全部弄懂,我这篇也没有必要看了.说了这么多,开始正文吧

【转】MATERIAL DESIGN设计规范学习心得

编者按:自学笔记就该这么做!今天分享@東門王三 同学关于Material Design的自学成果,他的学习笔记严谨有序,触类旁通,从Material Design到其他系统的设计规范都有所研究,还认真地做了思维导图,同学们可以边学习边借鉴他的自学方法,一举两得呦. 自学的一大重点就是读书,推荐同学们看一下华为设计总监的经验:<华为设计总监尤原庆:怎样读设计书> 想读好书的同学,可直接到:设计师图书导航 挑选. @東門王三 :随着Android系统从Android 4.4逐步升级到Android

Material Design 开发利器:Android Design Support Library 介绍

转自:https://blog.leancloud.cn/3306/ Android 5.0 Lollipop 是迄今为止最重大的一次发布,很大程度上是因为 material design —— 这是一门新的设计语言,它刷新了整个 Android 的用户体验.但是对于开发者来说,要设计出完全符合 material design 哲学的应用,是一个很大的挑战.Android Design Support Library 对此提供了很好的支持,里面汇集了很多重要的 material design 控

创建Material Design风格的Android应用--使用自定义动画

动画在Material Design设计中给用户反馈放用户点击时,并且在程序用户界面中提供连贯的视觉.Material主题为按钮(Button)和activity的转换提供了一些默认的动画,在android5.0(api 21)和更高的版本,你可以自定义这些动画和创建一个新动画: Touch feedback(触摸反馈) Circular Reveal(循环揭露效果) Activity transitions(Activity转换效果) Curved motion(曲线运动) View stat