最近在学习中用到了;浮动提示在EditText上的功能; 找了一圈;发现了 一个好用的 效果…..在这里记录下;
简单的实现浮动标签EditText:Android视图使用EditText之上,并提示EditText时填充文本。
参考项目地址:https://github.com/wrapp/floatlabelededittext
先看个人测试的效果:
下面直接使用方式:
方法一:直接添加库到AndoridStudio 中:
在app–>build.gradle 的 dependencies中直接添加:
dependencies {
//--部分略
//TJ:添加应用库-----
//TJ:EditText:文本框编辑的浮动提示
compile 'com.wrapp.floatlabelededittext:library:0.0.6'
}
然后 Sync Now…后 即可使用了 。 简单粗暴。
然后在要使用的地方:添加如下类似的操作代码即可:
完整的一个布局内容如:个人添加了四个选项功能
<?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"
xmlns:float="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<com.wrapp.floatlabelededittext.FloatLabeledEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:fletPaddingLeft="120dp"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is a test" />
</com.wrapp.floatlabelededittext.FloatLabeledEditText>
<!-- add some padding -->
<com.wrapp.floatlabelededittext.FloatLabeledEditText
android:id="@+id/floatEdit2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
float:fletPadding="10dp"
>
<EditText
android:id="@+id/edit2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
</com.wrapp.floatlabelededittext.FloatLabeledEditText>
<!-- password input -->
<com.wrapp.floatlabelededittext.FloatLabeledEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
float:fletPaddingBottom="10dp"
float:fletTextAppearance="@style/floatlabelededittext">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password" />
</com.wrapp.floatlabelededittext.FloatLabeledEditText>
<!-- change color of hint text-->
<com.wrapp.floatlabelededittext.FloatLabeledEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
float:fletPaddingBottom="10dp"
float:fletTextAppearance="@style/floatlabelededittext"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="PassWord Again"