I want to add a Drawable Image to my Button on the left and tried the following:
button = new Button(this);
button.setWidth(screen_dimens(0.25, "w")); //25% of screen width
button.setPadding(5, 5, 0, 5);
Drawable img = getResources().getDrawable(R.drawable.image);
button.setCompoundDrawablesWithIntrinsicBounds(img, null, null, null);
But I want to have a padding on the left between the drawable and the border of the button. Unfortunately, there is none.
Any help?
This will generate text + image button ( Image on Left & Text After That )
<Button
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:paddingLeft="20dp"
style="@style/whiteText"
android:onClick="openWhyAshoka"
android:drawableLeft="@drawable/arrow"
android:drawablePadding="50dp"
android:text="Ankit" />
You have to add the padding to you drawable, by changing the 9 slices content area or by changing your drawable padding:
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
If you are using selector you have to add the padding rule to each one of the drawable states.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With