setTransformationMethod(TransformationMethod)
当然,你自己要实现一个TransformationMethod接口,不要做转换。setTransformationMethod完了之后,可能密码还是不会变成明文,此时你把EditText里面的字符剪切出来,再粘贴进去,就行了。

解决方案 »

  1.   

            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
    mEtPassword.setInputType(InputType.TYPE_CLASS_TEXT);
    mEtPassword.postInvalidate();
    }
            
            });
      

  2.   

    或者
    可以实现动态切换,点一下显示,再点一下隐藏
            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没实现此功能,还请知道的告知一声,多谢!
      

  3.   

    我用这两个  et_password.setTransformationMethod(SingleLineTransformationMethod.getInstance());et_password.setTransformationMethod(PasswordTransformationMethod.getInstance());
      

  4.   

    不是刷新的问题,postInvalidate()是用在非UI线程里面用来刷新UI的。去掉也没关系,我试过了。
    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.
      

  5.   

    用SingleLineTransformationMethod也可以,只要是重新设置了属性不是PasswordTransformationMethod就可以。