Reputation: 11
Hi i have set an image in button using the following code. But am failing to add multiple images to the button
btn.setCompoundDrawablesWithIntrinsicBounds(null, null, null, getResources().getDrawable(R.drawable.red));
any one can tell me how to set multiple images in button ?
Upvotes: 1
Views: 1317
Reputation: 810
You can use ImageButton or use background in normal button
<Button
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/noproductimage"
/>
Upvotes: -1
Reputation: 6697
You are passing wrong arguments to setCompoundDrawablesWithIntrinsicBounds..you need to pass resource ids ,while your are passing null for first three and drawable to fourth one..
You need to call
btn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.left,R.drawable.right,R.drawable.top,R.drawable.left.bottom)
From the android documentation
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.
Related XML Attributes android:drawableLeft android:drawableTop android:drawableRight android:drawableBottom Parameters left Resource identifier of the left Drawable. top Resource identifier of the top Drawable. right Resource identifier of the right Drawable. bottom Resource identifier of the bottom Drawable.
Upvotes: 3