Android中Design库之TextInputLayout、TextInputEditText

时间不会辜负每一个平静努力的人!

欢迎来到周建的博客: 共同致力于技术分享与交流

首先上一张效果图:

这里写图片描述

布局文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/text_phone_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColorHint="@color/buttoncolor"
app:counterEnabled="true"
app:counterMaxLength="11"
app:counterTextAppearance="@style/MyStyle"
app:counterOverflowTextAppearance="@style/MyOverStyle">
<android.support.design.widget.TextInputEditText
android:id="@+id/text_phone"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="15sp"
android:hint="手机号码"
android:inputType="number"
android:textColor="@color/buttoncolor"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/text_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColorHint="@color/buttoncolor"
app:passwordToggleDrawable="@mipmap/eye"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/buttoncolor"
app:counterEnabled="true"
app:counterMaxLength="6"
app:counterTextAppearance="@style/MyStyle"
app:counterOverflowTextAppearance="@style/MyOverStyle">
<android.support.design.widget.TextInputEditText
android:id="@+id/text_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="密码"
android:textSize="15sp"
android:inputType="textPassword"
android:singleLine="true"
android:textColor="@color/buttoncolor"/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="50dp"
android:background="@color/buttoncolor"
android:text="登录"
android:textColor="@color/textColor"/>
</LinearLayout>

###源码下载

源码下载:https://github.com/zeke123/TextInputLayout