可绘制的左侧图标将变为不可见

  • 本文关键字:图标 绘制 android
  • 更新时间 :
  • 英文 :


我在编辑文本中添加了可绘制的左右图标。可绘制的右边用于显示或隐藏密码,但是当我单击可绘制的右图标时,可绘制的左边变得不可见。如何解决这个问题?

txtPassword.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int DRAWABLE_RIGHT = 2;
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (event.getRawX() >= (txtPassword.getRight() - txtPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                    if (IsHidePwd) {
                        txtPassword.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_show_pwd, 0);
                        txtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
                        IsHidePwd = false;
                        return true;
                    } else {
                        txtPassword.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_hide_pwd, 0);
                        txtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                        IsHidePwd = true;
                        return true;
                    }
                }
            }
            return false;
        }
    });

在这一行中,我认为您还需要为左侧设置可绘制对象。

txtPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.left_img, 0, R.drawable.ic_show_pwd, 0(;

最新更新