//内容可见

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

 

相关文章:

  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2021-12-17
  • 2022-12-23
  • 2022-03-15
猜你喜欢
  • 2021-04-13
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案