Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set property "android:drawableTop" of a button at runtime

Tags:

android

layout

How to set property "android:drawableTop" of a button at runtime

like image 721
Maneesh Avatar asked Feb 07 '11 09:02

Maneesh


2 Answers

Use

button.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

If you use

button.setCompoundDrawables(left, top, right, bottom);

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use null if you do not want a Drawable there. The Drawables must already have had setBounds(Rect) called.

like image 70
Tanmay Mandal Avatar answered Sep 26 '22 19:09

Tanmay Mandal


Drawable top = getResources().getDrawable(R.drawable.image); button.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null); 
like image 44
Kirit Vaghela Avatar answered Sep 22 '22 19:09

Kirit Vaghela