Android 更改编辑文本的可绘制权限的步骤

Android 更改编辑文本的可绘制权限的步骤,android,onclick,android-drawable,Android,Onclick,Android Drawable,我正在尝试更改EditText中的drawable,因为它在图像中 我正在使用下面的代码使绘图可点击 password_editText.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0;

我正在尝试更改EditText中的drawable,因为它在图像中

我正在使用下面的代码使绘图可点击

 password_editText.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                final int DRAWABLE_LEFT = 0;
                final int DRAWABLE_TOP = 1;
                final int DRAWABLE_RIGHT = 2;
                final int DRAWABLE_BOTTOM = 3;

                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (event.getRawX() >= (password_editText.getRight() - password_editText
                            .getCompoundDrawables()[DRAWABLE_RIGHT].getBounds()
                            .width())) {
                        // your action here
                        Toast.makeText(MainActivity.this, "drawable click",
                                Toast.LENGTH_LONG).show();



                        return true;
                    }
                }
                return false;
            }
        });

在这里,我想更改密码列中的绘图,以便在单击时更改

您可以在运行时使用

Drawable img = getContext().getResources().getDrawable( R.drawable.your_drawable );

password_editText.setCompoundDrawables( null, null, img, null ); 

您可以使用SetCompoundDrawableSwithinInstincBounds函数:

password_editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.yourdrawable, 0);
参数的顺序:左、上、右、下