et = (EditText) findViewById(R.id.et);
CheckBox box = (CheckBox) findViewById(R.id.check);
box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
et.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
} else {
et.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
et.setSelection(et.getText().length());
}
});
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="60dp"
android:inputType="textPassword" />
<CheckBox
android:id="@+id/check"
android:layout_width="30dp"
android:layout_height="30dp"
android:button="@drawable/show_selector"
android:checked="false" />
</LinearLayout>
控制密码输入框可见不可见
最新推荐文章于 2022-01-26 23:57:38 发布