3.22 打勾显示输入的密码 --EditText与setTransformationMethod
实现目标:
android:id="@+id/et"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:phoneNumber="true"
android:maxLength="11"/>
实现原理:
为CheckBox添加一个监听器事件;
实现的源码:
package edu.cquptzx.showPassword;
import android.app.Activity;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
publicclass ShowPasswordActivityextends Activity {
private EditTextedittext;
private CheckBoxcheckbox;
/** Called when the activity is first created. */
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*find the object by IDs .*/
edittext = (EditText) findViewById(R.id.et);
checkbox = (CheckBox) findViewById(R.id.cb);
/* add a listener to the CheckBox */
checkbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
{
publicvoid onCheckedChanged(CompoundButton buttonView,boolean isChecked)
{
if(checkbox.isChecked())
{
/* show the password*/
edittext.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}
else
{
/* hide the password */
edittext.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});
}
}
相关知识:
最后实现效果:
EditText 密码显示 隐藏三种方法
(2013-03-07 18:31:58)CheckBox ck_ps=null;
EditText ed_input=null;
...
ck_ps.setOnCheckedChangeListen