【问题标题】:How to show hidden password in textview? [closed]如何在textview中显示隐藏密码? [关闭]
【发布时间】:2012-08-08 22:10:03
【问题描述】:

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

【问题讨论】:

  • 你想要什么我没有得到
  • 我已经编辑了我的帖子,也许现在可以理解了

标签: android


【解决方案1】:

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

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

if (isChecked) {
            // This will display plain-text
            edittextPassword
                    .setTransformationMethod(SingleLineTransformationMethod
                            .getInstance());
        } else {
            // This will display *******
            edittextPassword
                    .setTransformationMethod(PasswordTransformationMethod
                            .getInstance());
        }    
}

【讨论】:

    【解决方案2】:

    我不确定我是否理解您的问题,但根据标题,此示例应该对您有所帮助:

    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);
    }});
    

    【讨论】:

      猜你喜欢
      • 2011-06-10
      • 2018-08-13
      • 2021-02-26
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 2018-01-15
      相关资源
      最近更新 更多