2

platform app using Xamarin PCL project. I have created a button with image and no text.

 <Button Image="{DynamicResource ProfileImage}" Grid.Row="0" Grid.Column="2" BackgroundColor="Transparent" x:Name="dashboard" StyleId="dashboard" HorizontalOptions="Center" Clicked="TabClicked"></Button>

I am facing some UI Issue. In windows 10,it looks like -

enter image description here

In android, it looks like-

enter image description here

Is there any way to remove this outline border from android.

Sonali
  • 2,223
  • 6
  • 32
  • 69

4 Answers4

1

I removed the border/shadow from buttons in Android by setting its elevation to 0px with the help of this link

class MyButtonRenderer : ButtonRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged(e);
            try
            {
                if (Control != null)
                {
                    Control.Elevation = 0;
                }
            }
            catch(Exception ex){}
        }
    }
Community
  • 1
  • 1
Sonali
  • 2,223
  • 6
  • 32
  • 69
0

Have you tried setting BorderColor="Transparent" on your button XAML?

Zroq
  • 8,002
  • 3
  • 26
  • 37
0

To remove background of an image completely, you can use Image view type instead of Button.

You can arrange it's source:

<StackLayout Padding="15,5,0,5">
      <Image x:Name="MyImage"  Source="myImage.png"/>
</StackLayout>

And you can add a click method it easily:

var gestureRecognizerForImage = new TapGestureRecognizer();
gestureRecognizerForImage.Tapped += MyImageClicked;
MyImage.GestureRecognizers.Add(gestureRecognizerForImage);

 public async void GetMediaClicked(object sender, EventArgs e)
 {
     await DisplayAlert("Clicked", "My Image is Clicked", "OK");
 }
Onur
  • 247
  • 3
  • 13
0

You can set BorderWidth = 0. It should remove the border.

Daniel
  • 9,312
  • 3
  • 48
  • 48