EditText 隐藏或者显示输入内容

public class MainActivity extends Activity   
{  
    private EditText password=null;  
    private CheckBox check=null;  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState)   
    {         
        super.onCreate(savedInstanceState);  
        super.setContentView(R.layout.activity_main);  
        this.password=(EditText)super.findViewById(R.id.password);  
        this.check=(CheckBox)super.findViewById(R.id.check);  
        //为check设置监听选项,控制密码框的显示方式  
        this.check.setOnClickListener(new OnClickListener()  
        {     
            @Override  
            public void onClick(View v)   
            {  
                if(check.isChecked())  
                {  
                    //设置密码可见  
                    password.setTransformationMethod(HideReturnsTransformationMethod.getInstance());  
                }  
                else  
                {  
                    //设置密码隐藏  
                    password.setTransformationMethod(PasswordTransformationMethod.getInstance());  
                }  
            }  
        });  
    }  
  
}  

 

posted @ 2016-02-18 17:35  _启明  阅读(937)  评论(0编辑  收藏  举报