0

我打开了一个edittext对话框的textview onclick,其中inputtype是密码。但是在单击对话框确定按钮后,edittext 值在 textview 上设置,但如果是密码,它会在 textview 上显示任何文本,知道如何在 android 的 textview 上设置隐藏文本(密码)吗?

4

2 回答 2

5

我想我理解您的要求...如果这不正确,请尝试更具体...您的英语有点难以理解。

我用一个复选框做到了这一点。你可以将你的代码绑定到任何东西......但这是最好的方法(如果它是你正在寻找的)

if (isChecked) {
            // This will display plain-text
            edittextPassword
                    .setTransformationMethod(SingleLineTransformationMethod
                            .getInstance());
        } else {
            // This will display *******
            edittextPassword
                    .setTransformationMethod(PasswordTransformationMethod
                            .getInstance());
        }    
}
于 2012-08-08T13:50:11.260 回答
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);
}});
于 2012-08-08T14:04:41.623 回答