I created a Xamarin form cross-platform application for Android and iOS operating systems. I had to add a gradient to appbars on the OS (called toolbars on iOS Android and UINavigationBar) and was wondering if there was a way to do it. Please help me with that. Anything.

enter image description here

You should customize the render like this:

In your PCL or shared project:

Public class navigationpagegradientheader: navigationpage {public navigationpagegradientheader root (web page) : the base (root) {}

Public static read-only BindableProperty RightColorProperty = BindableProperty. Create (name of the property name: (rightcolor), type: type (color), declaringtype: type (navigationpagegradientheader), default: color. Public static read-only BindableProperty LeftColorProperty = bindableProperty. Create (name of the property name: (leftcolor), type: type (color), declaringtype: type (navigationpagegradientheader), default: color. Public color rightcolor {get {return (color) method (rightColorProperty)} configuration {assign (rightColorProperty, Value)}} Public color leftcolor {get {return (color) method (leftColorProperty)} configuration {assign (leftColorProperty, value)}}Copy the code

} update

Because “Dehan Wjiesekara is keen on this issue I’ve taken the time to create an example and you can see it on GitHub.

Then in your Android project:

【 assembly: exportrenderer (type (navigationpagegradientheader), type (navigationpagegradientheaderrenderer))] namespace yournamespace. Robot {public class navigationpagegradientheaderrenderer: Navigationrenderer {protected override invalid onelementChanged (elementChangeDeventargs < navigationPage >E) {base. Onelementchanged (E)

/ / The runtime creates the element if (E. oldelement ! = = = invalid | | element invalid) {return} = VaR control device (navigationpagegradientheader) it. Element VaR context = (main activity) this. Context context. ActionBar. Setbackgrounddrawable (new Gradientdrawable). Direction. From right to left, new int[] {controls. Rightcolor. Android (), control device. Leftcolor. Android ()})}Copy the code

} If you use formsappActivity in your main activity just add a Drawable in gradient like this:

< form XMLNS: Android= “HTTP: / / / / / schemas.android.com APK Android.” Android: Shape = “rectangle” >

< gradient Android: Angle = “180” Android: endcolor= “# 109f8D” Android: startColor = “# 36ED81” Android: Type = “linear” >

< / shape > then call this drawable in your tool. axml file:

< android. Support. V7. Widget. The toolbar XMLNS: android = “HTTP: / / / / / schemas.android.com APK android.” Android: ID= “@ID/Toolbar” Android: Layout_width = “match_parent” Android: Layoutheight = “Wrap happy” Android: Background = “drawable/gradient” Android: Theme = “@style/themeoverlay. Appcompat ActionBar. Dark.” Android: popuptheme= “@style/themeoverlay. Appcompat.” > In your iOS project:

【 assembly: exportrenderer (type (navigationpagegradientheader), type (navigationpagegradientheaderrenderer))] namespace yournamespace. IOS {public class navigationpagegradientheaderrenderer: navigationrenderer {public rewrite invalid viewwillappear (Boolean animation) {base. Viewwillappear (Animation)

= (navigationpagegradientheader) the VaR control device. Element VaR gradientlayer = New CagRadientLayer () gradientlayer. Bounds = navigation bar. Boundary gradient layer. Color = new CGcolor [] {control device. Rightcolor. Tocgcolor (), control device. Leftcolor. Tocgcolor ()} Gradient layer. Starting point and ending point = new CGpoint (zero, zero point five) gradient layer. Endpoint = new CGPoint (" 1 ", zero point five) uigraphics. Beginimagecontext (Gradient layer. Boundaries. Size) gradient layer. Renderincontext (uigraphics. Getcurrentcontext ()) UIImage Image = uigraphics. Getimagefromcurrentimagecontext uigraphics (). Endimagecontext () navigation bar. Setbackgroundimage (image, uibarmetrics. Default)}}Copy the code

} Finally in your code file file call this control like this:

Page = new navigationpagegradientheader new home page () () {leftcolor = color. Fromhex (” # 109F8D “), rightColor = color. Fromhex (” # 36ed81 “)}

enter image description here



www.apkbus.com/blog-919651…