EditText密码输入框中密码的显示与隐藏

通过自定义EditText进行处理,对文本框进行判断密码是否显示
design新特性TextInputLayout情况下的自定义edittext与一般情况下的edittext比较
效果图:

Paste_Image.png
Paste_Image.png

自定义EditText的代码:

Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png
Paste_Image.png

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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容