美文网首页程序员工具癖@IT·互联网
EditText密码输入框中密码的显示与隐藏

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

作者: 神山上人 | 来源:发表于2016-10-10 09:01 被阅读0次

    通过自定义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>

    相关文章

      网友评论

        本文标题:EditText密码输入框中密码的显示与隐藏

        本文链接:https://www.haomeiwen.com/subject/vuvmyttx.html