Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 79144

Frame doesn't have shadow effect below API Level 28 Android

$
0
0

I've created a custom renderer for Frame to feel like CardView in Android it works fine on Android P but i've tested on API 21,22,23 it doesn't have any kind of effect. Here is my Android Renderer.

    public class ShadowFrameRenderer : Xamarin.Forms.Platform.Android.AppCompat.FrameRenderer
    {
        public ShadowFrameRenderer(Context context) : base(context)
        {
        }
        protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
        {
            base.OnElementChanged(e);
            if (e.NewElement != null && e.NewElement is ShadowFrame)
            {
                Elevation = 30.0f;
                TranslationZ = 0.0f;
                SetZ(30f);
                //this.SetBackgroundResource(Resource.Drawable.shadow);
                //GradientDrawable drawable = (GradientDrawable)this.Background;
                //drawable.SetColor(Android.Graphics.Color.ParseColor("#F0F0F0"));
            }
            UpdateElevation();
        }


        private void UpdateElevation()
        {
            //var materialFrame = (ShadowFrame)Element;

            // we need to reset the StateListAnimator to override the setting of Elevation on touch down and release.
            if(Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            Control.StateListAnimator = new Android.Animation.StateListAnimator();

            // set the elevation manually

                ViewCompat.SetElevation(this, 10);
                ViewCompat.SetElevation(Control, 10);
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                Control.Elevation = 10;
                Control.CardElevation = 10;
            }

        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            UpdateElevation();
            //if (e.PropertyName == "Elevation")
            //{
            //    UpdateElevation();
            //}
            }


Viewing all articles
Browse latest Browse all 79144

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>