Question Detail

I required doing DrawableRight programmatically because it changes as per some condition.

<TextView
    android:id="@+id/fcoin_TextView_ID"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawablePadding="@dimen/btn_margin"
    android:drawableRight="@drawable/fccsmall"
    android:gravity="center|left"
    android:text="00" />

I can use this but need to change in every condition:

I have tried Something like below code but not Succeed. Please Correct me 

fc_TextView.setCompoundDrawables(getResources().getDrawable(R.drawable.ic_coin),null,null,null);


Thread Reply

Correct Answer

Hemant Sharma

- 1 years ago

You need to use CompoundDrawablesWithIntrinsicBounds

fc_TextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_coin, 0);