Reputation: 3347
Since on button, we can use android:drawableLeft to set the drawable on the left of a button. Is there way to get this drawable programmatically?
<Button android:id="@+id/detail_refresh_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/refresh"
android:gravity="center"
android:drawableLeft="@drawable/progress"
/>
Is there any way to get the drawable "progress" in Java code?
Upvotes: 10
Views: 9870
Reputation: 37342
Button.getCompoundDrawables()[index]
where index
can be 0, 1, 2, 3 for drawableLeft
, drawableTop
, drawableRight
, drawableBottom
respectively.
Upvotes: 0
Reputation: 44
If the view is button,
button.getBackground().setLevel(x);
imageView.getDrawable().setLevel(x);
Upvotes: 0
Reputation: 4187
Looking at : http://developer.android.com/reference/android/widget/Button.html
You can see that
myButton.setCompoundDrawablesWithIntrinsicBounds(Drawable,Drawable,Drawable,Drawable)
Should give you what your looking for.
Order: Left, top, right, and bottom
Upvotes: 3