Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to change transparency of "Xamarin.Forms Material Visual" disabled button?

kavi93kavi93 Member ✭✭
edited September 25 in Xamarin.Forms

I would like to change the transparency level of the disabled button.

Disabled Button View

Enabled Button View

`[assembly: ExportRenderer(typeof(LabelButton), typeof(SkyRacing.Droid.LabelButtonRenderer))]
namespace SkyRacing.Droid
{
public class LabelButtonRenderer : MaterialButtonRenderer
{
public LabelButtonRenderer(Context ctx) : base(ctx)
{

    }

    protected override void OnDraw(Android.Graphics.Canvas canvas)
    {
        base.OnDraw(canvas);

        if (!Element.IsEnabled)
            Element.Opacity = 0.9;
    }

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);

        if (e.PropertyName == nameof(Xamarin.Forms.Button.IsEnabled))
        {
            if (!Element.IsEnabled)
                Element.Opacity = 0.9;
        }
    }
}

}`

I've tried creating a custom renderer and changing the opacity of the disabled button to 0.9 but still, it is too transparent. How can reduce the transparency level of the button? (FYI, on debug mode I've inspected the Element property. It is already 1 even before I set to 0.9, wonder how it is too much transparent).

Answers

  • jezhjezh Member, Xamarin Team Xamurai
    edited September 29

    Have you tried the property Opacity of Button?

       Opacity="0.5"
    

    Besides, what's the LabelButton in your code ? Could you please post the code of LabelButton?

Sign In or Register to comment.