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

Android 21 Elevation - anyone with any luck implementing?

$
0
0

I have been working with Lollipop for a bit now, and am able to get much of the material design working for me (statusbarcolor and navigationbarcolor as an example).

I'm trying to write a custom renderer for Elevation on a ContentView, but when it renders, I don't actually see any shadow. Has anyone gotten this to work successfully? What did you do?

using System.ComponentModel;
using TimeTracker.Controls;
using TimeTracker.Droid.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using View = Android.Views.View;

[assembly: ExportRenderer(typeof(ExtendedContentView), typeof(ExtendedContentViewRenderer))]
namespace TimeTracker.Droid.Renderers
{
    public class ExtendedContentViewRenderer : ViewRenderer<ContentView, View>
    {

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (Control != null)
            {
                Control.Elevation = ((ExtendedContentView)Element).Elevation;
                Control.TranslationZ = ((ExtendedContentView)Element).Elevation;
            }
        }
    }
}
using Xamarin.Forms;

namespace TimeTracker.Controls
{
    public class ExtendedContentView : ContentView
    {
        public static readonly BindableProperty ElevationProperty = BindableProperty.Create<ExtendedLabel, float>(p => p.Elevation, 0f);
        public float Elevation
        {
            get { return (float)GetValue(ElevationProperty); }
            set { SetValue(ElevationProperty, value); }
        }
    }
}
public class TaskTileTemplate : ContentView
{
    private readonly Constraint _centerX = Constraint.RelativeToParent(parent => parent.Width / 2);
    private readonly Constraint _centerY = Constraint.RelativeToParent(parent => parent.Height / 2);

    public TaskTileTemplate(object item)
    {
        BindingContext = item;

        // snip

        var tile = new ExtendedContentView
        {
            Content = innerLayout,
            VerticalOptions = LayoutOptions.FillAndExpand,
            Elevation = 3                                                               //<- here
        };

        tile.SetBinding(BackgroundColorProperty, "Color", BindingMode.OneWay, new HexToColorConverter());

        Content = tile;
    }
}

Essentially I want to get some elevation on the square tiles (Meetings, Development, Break), and once I get that going, I want elevation on the numbers and stop button as well.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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