//内容可见
mEtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
//内容不可见
mEtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
private Button mBtnPassword; private EditText mEtPassword; private boolean mbDisplayFlg = false; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); 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) { // display password text, for example "123456" mEtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { // hide password, display "." mEtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance()); } mbDisplayFlg = !mbDisplayFlg; mEtPassword.postInvalidate(); } }); }