I am writing a button custom renderer for my Xamarin app. Therefore I inherit from the class ButtonRenderer and use the Control to customize my button. I need two images in this button, on the left and on the right. In the middle there is a text label. How do I get a second image in the button in the C#-Class (not in xaml)
0
votes
1 Answers
0
votes
You could use the SetCompoundDrawablesWithIntrinsicBounds
method to add images to the top, bottom, left and right of the Button
for Android .
class MyButtonRenderer :ButtonRenderer
{
public MyButtonRenderer(Context context) : base(context) { }
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged(e);
if (Control !=null)
{
Control.SetCompoundDrawablesWithIntrinsicBounds(Resources.GetDrawable(Resource.Drawable.fivePlus), null, Resources.GetDrawable(Resource.Drawable.fivePlus), null);
}
}
}