Issue
I'm working on a Xamarin Android app and I'm setting the following style to a button through my styles.xml
<style name="button_style_1" parent="@style/button_style_default">
<item name="android:drawableLeft">@drawable/my_icon</item>
<item name="android:drawablePadding">28dp</item>
<item name="android:padding">5dp</item>
</style>
Everything works fine but now I need to set the above properties to my button programmatically. What's the best way to do it in Xamarin.Android?
Solution
For drawableLeft
var draw = ContextCompat.Drawable(this, Resource.Drawable.your_drawable)
button.SetCompoundDrawablesWithIntrinsicBounds(draw, null, null, null);
Note :
this
is context of the Activity.
For drawablePadding
use CompoundDrawablePadding
.
For padding
use SetPadding
.
Important Note :
CompoundDrawablePadding
with anegative padding
andSetPadding
with apositive padding
to counter creates acentered effect
.
just check it out and tell me.
Answered By - Harshad Pansuriya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.