class:
private EditText et_pwd; et_pwd = (EditText) findViewById(R.id.et_pwd);
private CheckBox cb_eye; cb_eye = (CheckBox) findViewById(R.id.cb_eye);
//密码显示隐藏
cb_eye.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {//选中隐藏
et_pwd.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
}else {
et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
}
}
});
layout:
<EditText
android:id="@+id/et_pwd"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="45dp"
android:layout_marginLeft="10dp"
android:padding="10dp"
android:background="@null"
android:maxLength="16"
android:singleLine="true"
android:password="true"
android:hint="请输入登录密码"
android:textSize="15sp" />
<CheckBox
android:id="@+id/cb_eye"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_gravity="center"
android:checked="true"
android:button="@drawable/cb_eye_select" />