Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get drawable from a button?

Tags:

android

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?

like image 903
PixelsTech Avatar asked Oct 30 '12 19:10

PixelsTech


People also ask

How do you call drawable on android?

But Best way to do is :R. drawable. ic_delete); OR use the below code for Drawable left, top, right, bottom.

How to link buttons in android studio?

Simple. Just put the link in your TextView. Note: The most important property here is android:autoLink="all" . This allow you to link to urls, emails and phone numbers.


2 Answers

I think you want Button.getCompoundDrawables()[0]

like image 116
JeffS Avatar answered Oct 10 '22 00:10

JeffS


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

like image 32
Broak Avatar answered Oct 10 '22 00:10

Broak