我有一个textview onclick,打开一个edittext对话框,其中inputtype是password。 但点击对话框后确定按钮edittext值是在textview上设置的,但是在密码的情况下,它在textview上显示任何文本,任何想法如何在android中的textview上设置隐藏文本(密码)?
答案 0 :(得分:5)
我想我理解你的要求......如果这不对,那就试着更具体一点......你的英语有点难以理解。
我用复选框做了这个。您可以将代码绑定到任何...但这是最好的方法(如果它是您正在寻找的)
if (isChecked) {
// This will display plain-text
edittextPassword
.setTransformationMethod(SingleLineTransformationMethod
.getInstance());
} else {
// This will display *******
edittextPassword
.setTransformationMethod(PasswordTransformationMethod
.getInstance());
}
}
答案 1 :(得分:1)
我不确定我是否理解您的问题,但根据标题,此示例应该对您有所帮助:
EditText pass = (EditText) findViewById(R.id.password);
pass.setTypeface(Typeface.DEFAULT);
View showPass = findViewById(R.id.show_pass_checkbox);
showPass.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String textValue = pass.getText().toString();
if (((CheckBox) v).isChecked()) {
pass.setText("");
pass.setInputType(InputType.TYPE_CLASS_TEXT);
}else {
pass.setText ("");
pass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
pass.setTypeface(Typeface.DEFAULT);
}
pass.setText(textValue);
}});