setTransformationMethod(TransformationMethod)
当然,你自己要实现一个TransformationMethod接口,不要做转换。setTransformationMethod完了之后,可能密码还是不会变成明文,此时你把EditText里面的字符剪切出来,再粘贴进去,就行了。
当然,你自己要实现一个TransformationMethod接口,不要做转换。setTransformationMethod完了之后,可能密码还是不会变成明文,此时你把EditText里面的字符剪切出来,再粘贴进去,就行了。
mBtnPassword = (Button)findViewById(R.id.btnPassword);
mBtnPassword.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
mEtPassword.setInputType(InputType.TYPE_CLASS_TEXT);
mEtPassword.postInvalidate();
}
});
可以实现动态切换,点一下显示,再点一下隐藏
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) {
mEtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
} else {
mEtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
mbDisplayFlg = !mbDisplayFlg;
mEtPassword.postInvalidate();
}
});
用setInputType没实现此功能,还请知道的告知一声,多谢!
public void postInvalidate ()
Since: API Level 1
Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.