我正在尝试更改EditText中的可绘制内容,就像在图像中一样。


我使用下面的代码来使这个可绘制的可点击。
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;
}
});在这一点上,我想更改密码列中的可绘制内容,以便在单击时更改。
发布于 2015-06-03 00:51:12
您可以在运行时使用以下命令更改可绘制
Drawable img = getContext().getResources().getDrawable( R.drawable.your_drawable );
password_editText.setCompoundDrawables( null, null, img, null ); 发布于 2015-06-03 03:35:09
您可以使用setCompoundDrawablesWithIntrinsicBounds函数:
password_editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.yourdrawable, 0);参数的顺序:左、上、右、下
https://stackoverflow.com/questions/30601662
复制相似问题