通过自定义EditText进行处理,对文本框进行判断密码是否显示
design新特性TextInputLayout情况下的自定义edittext与一般情况下的edittext比较
效果图:
自定义EditText的代码:
xml文件布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout android:id="@+id/main_ll_container_1" android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:" android:textSize="20sp" />
<com.example.asus.passwordedittext.view.PasswordEditText android:id="@+id/main_pet_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="请输入密码" />
</LinearLayout>
<android.support.design.widget.TextInputLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_below="@+id/main_ll_container_1"> <com.example.asus.passwordedittext.view.PasswordEditText android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="请输入密码" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
attrs自定义属性,在values文件夹下
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="PasswordEditText">
<attr name="pet_iconShow" format="integer"/>
<attr name="pet_iconHide" format="integer"/>
</declare-styleable
</resources>