Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the shadow of a button on Xamarin Forms

is it possible? I would like to remove the shadow of the buttons on Xamarin Forms.

Thanks

like image 377
Edu_LG Avatar asked Jul 20 '16 10:07

Edu_LG


People also ask

How to remove the Button shadow in Xamarin Forms?

For delete shadow on button Android you just need create a renderer in project Droid and set BackroundColor with transparent or other color. Incredible, i just created that class and the borders works and shadows was removed on android.

How do I get rid of shadows on Android?

If you want an Android app to remove shadow from photo, you can use Remove Unwanted Content. Just like other apps, this app offers two selection tools including the lasso and brush tools which allows you to select the shadow areas from your image.


3 Answers

For delete shadow on button Android you just need create a renderer in project Droid and set BackroundColor with transparent or other color.

For a project using PCL :

[assembly: ExportRenderer(typeof(Button),typeof(FlatButtonRenderer))]
namespace Project.Droid
    {
        public class FlatButtonRenderer : ButtonRenderer
        {
            protected override void OnDraw(Android.Graphics.Canvas canvas)
            {
                base.OnDraw(canvas);
            }
        }
    }

In XAML :

<Button BackgroundColor="Transparent" Text="ClickMe"/>
like image 197
Matthieu Lemonnier Avatar answered Oct 18 '22 23:10

Matthieu Lemonnier


Explaining with more detail.

using Android.App;
using Android.Content.PM;
using Android.OS;
using Xamarin.Forms.Platform.Android;
using ProjectName.Droid;
using Xamarin.Forms;

[assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(FlatButtonRenderer))]
namespace ProjectName.Droid
{    
    public class FlatButtonRenderer : ButtonRenderer
    {
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            base.OnDraw(canvas);
        }
    }
}
like image 30
JD - DC TECH Avatar answered Oct 19 '22 00:10

JD - DC TECH


@Tonatio in your renderer instead of using

[assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(FlatButtonRenderer))]

use this

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

you will have to make a CustomButton control that inherits from Xamarin.Forms.Button and then use that custom button in your xaml instead of regular button. that should do the thing

     //Add references to your custom control
        xmlns:controls="clr-namespace:YourNameSpace.Controls"
     //Use control
     <Grid>
           <controls:YourCustomButton x:Name="_customButton"/>
     </Grid>

Feel free to drop by if you need some more help.

like image 24
Aditya Deshpande Avatar answered Oct 18 '22 23:10

Aditya Deshpande