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

Gradient Background on Android

$
0
0

I have a PageRenderer

public class GradientContentPageRenderer : PageRenderer 
    {
        protected override void OnElementChanged (ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged (e);
            if (e.OldElement == null) 
            {
                SetBackgroundResource (Resource.Drawable.gradient);
            }
        }
    }

The drawable file (drawable/gradient.xml) looks like this

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    <gradient android:angle="-90"
              android:type="linear"
              android:startColor="#16B0F9"
              android:endColor="#16D9F9"/>
</shape>

The XAML looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<renderer:GradientContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:renderer="clr-namespace:Mobile.Views.CustomRenderers;assembly=Mobile"
    xmlns:resources="clr-namespace:Mobile.Resources;assembly=Mobile"
    x:Class="Mobile.Pages.LoginPage">
    <ContentPage.Content>
        ..
        ..
        ..
</renderer:GradientContentPage >

But when I run the app, the background does not change. Any help would be appreciated.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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