EditText 密码属性

        <EditText
                android:id="@+id/et_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@null"
                android:hint="密码"
                android:inputType="textPassword"
                android:padding="5dp"
                android:textSize="14sp" />

            <CheckBox
                android:id="@+id/cb_password_vis"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:button="@drawable/password_selector" />
    
View Code
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@mipmap/icon_visible_passwords_ng" android:state_checked="true" />
    <item android:drawable="@mipmap/icon_invisible_ng" android:state_checked="false" />
</selector>
password_selector.xml
 cbPasswordVis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    etPassword.setInputType(InputType.TYPE_CLASS_TEXT);
                }else{
                    etPassword.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            }
        });
View Code

 

posted on 2016-11-28 20:29  语风6649  阅读(1090)  评论(0编辑  收藏  举报

导航