博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

005、打钩显示输入密码

Posted on 2013-09-16 16:28  mz_zyh  阅读(236)  评论(0编辑  收藏  举报
通过CheckBox.setOnCheckedChangeListener()方法来设置EditText显示密码事件
EditText的setTransformationMethod()方法是用以设置其显示的字符类型。
HideReturnsTransformationMethod.getInstance():正常显示所输入的密码字符;
PasswordTransformationMethod.getinstance():隐藏输入的字符,恢复为密码输入状态。 
 
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transformation_method);
        ((CheckBox) findViewById(R.id.cb))
                .setOnCheckedChangeListener(new OnCheckedChangeListener() {
 
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView,
                            boolean isChecked) {
                        if (isChecked) {
                            ((EditText) findViewById(R.id.et))
                                    .setTransformationMethod(HideReturnsTransformationMethod
                                            .getInstance());
                        } else {
                            ((EditText) findViewById(R.id.et))
                                    .setTransformationMethod(PasswordTransformationMethod
                                            .getInstance());
                        }
                    }
                });
 
    }