通过EditText的setTransformationMethod()隐藏或显示密码

    private Button mBtnPassword;
private EditText mEtPassword;
private boolean mbDisplayFlg = false; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); mEtPassword = (EditText)findViewById(R.id.password);
mBtnPassword = (Button)findViewById(R.id.btnPassword);
mBtnPassword.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("AndroidTest", "mbDisplayFlg = " + mbDisplayFlg);
if (!mbDisplayFlg) {
// display password text, for example "123456"
mEtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
} else {
// hide password, display "."
mEtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
mbDisplayFlg = !mbDisplayFlg;
mEtPassword.postInvalidate();
} }); }
上一篇:扫描二维码的实现(barcode) ---- HTML5+


下一篇:如何在maven中添加本地jar包