Android登录密码-明文/密文切换

 /**
     * 切换明文密码
     * @param editText  需要切换显示的EditText数据
     * @param showImageView 切换显示数据的图片
     *isHidden 就是一个明文密文切换的开关
     */
    protected boolean isHidden =true;
    protected void showPwd(EditText editText, ImageView showImageView){
        if(isHidden){
            //editText可见
            editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
            /**图标改变*/
            showImageView.setImageResource(R.drawable.icon_hand_take);
        } else {
            //editText不可见
            editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
            /**图标改变*/
            showImageView.setImageResource(R.drawable.ic_launcher);
        }
        isHidden =!isHidden;
        editText.postInvalidate();
        //切换后将EditText光标置于末尾
        CharSequence charSequence = editText.getText();
        if (charSequence instanceof Spannable) {
            Spannable spanText = (Spannable) charSequence;
            Selection.setSelection(spanText, charSequence.length());
        }
    }