Android 中的 getCompoundDrawables() 是什么?

What is getCompoundDrawables() in Android?

如何在 Android 中使用 getCompoundDrawables()

if(mEditText.getCompoundDrawables()[2] == null)
    mEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_face, 0);

我想看看在EditText的最后是否有drawable。 if 条件是否给出正确的结果?

是的,这是确定是否设置了复合可绘制对象的正确方法。

是的,你可以。

Drawable drawable =  getActivity().getResources().getDrawable(R.drawable.ic_face);
drawable.setBounds(new Rect(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()));
if(mEditText.getCompoundDrawables()[2] == null)
 {
    mEditText.setCompoundDrawables(null, null, drawable, null);
 }
mEditText.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Drawable co =  v.getCompoundDrawables()[2];
        if (co == null) {
            return false;
        }
        if (event.getAction() != MotionEvent.ACTION_DOWN) {
            return false;
        }
        if (event.getX() > v.getMeasuredWidth() - v.getPaddingRight()
                - co.getIntrinsicWidth()) {
            //code for right drawable event
            return true;
        } else {
            return false;
        }
    }
});