今天,主要是看见朋友的软件的输入框,提示信息会自动向上弹,而不是消失,就问他要了控件,
写了一下效果还不错,这里和大家分享下。
这里主要是用到了 新控件FloatLabeledEditText
下面我就简单的说下用法首先添加依赖
compile'com.wrapp.floatlabelededittext:library:0.0.6'
然后是应用了这里我给大家xml文件
<?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:tools="http://schemas.android.com/tools"
xmlns:float="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_main"
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">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is the hint" />
</com.wrapp.floatlabelededittext.FloatLabeledEditText>
<!-- add some padding 添加了一些间距 -->
<com.wrapp.floatlabelededittext.FloatLabeledEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
float:fletPadding="10dp">
<EditText
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">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
</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="Styled Hint"
android:inputType="textPassword" />
</com.wrapp.floatlabelededittext.FloatLabeledEditText>
</LinearLayout>
下面再给出一些用到的
xmlns:float="http://schemas.android.com/apk/res-auto"
这个是最后一个变色的style
<style name="floatlabelededittext">
<item name="android:textColor">#FF0000</item>
</style>
然后运行就可以了 是不是特别简单好用O(∩_∩)O哈哈~