Swapnil Khandode
Swapnil Khandode

Reputation: 1

Remove shadow from Android Button built in Xamarin forms

I am trying to get rid of the shadow that is being displayed at the bottom of a button in android built using xamarin forms. I have tried all that I could. But I have not achieved it. I have attached an image for reference. I request your'l to help me and put me out of my misery. Thanks in advance

enter image description here

Upvotes: 0

Views: 1179

Answers (3)

Breeno
Breeno

Reputation: 3176

For me, only thing that removed the shadow was doing this in a custom button render:

Control.StateListAnimator = null;

It may be dependent on API level, though, so might also require:

Control.Elevation = 0;

Upvotes: 0

Ufuk Zimmerman
Ufuk Zimmerman

Reputation: 520

1) Create custom control and derive it from Button.

   public class ButtonWithoutShadow : Button
 {
 }

2) Create custom renderer

 [assembly: ExportRenderer(typeof(ButtonWithoutShadow), typeof(ButtonWithoutShadowRenderer))]
public class ButtonWithoutShadowRenderer : ButtonRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            Control.Elevation = 0;
        }

    }
}

3) In xaml page use this button:

<controls:ButtonWithoutShadow TextColor="White" HorizontalOptions="Center" WidthRequest="185" HeightRequest="52" BackgroundColor="#ffcd00" Font="Roboto-Regular" FontSize="23" Text="Поиск" BorderRadius="0" BorderWidth="0" />

Upvotes: 1

Ufuk Zimmerman
Ufuk Zimmerman

Reputation: 520

[assembly: ExportRenderer(typeof(Button),typeof(FlatButtonRenderer))]

namespace Project.Droid

 {
        public class FlatButtonRenderer : ButtonRenderer
        {
            protected override void OnDraw(Android.Graphics.Canvas canvas)
            {
                base.OnDraw(canvas);
            }
        }
    }

<Button BackgroundColor="Transparent" Text="ClickMe"/>

Source : https://stackoverflow.com/a/39966574/7794690

Upvotes: 0

Related Questions