In Android platform, we need to create file shadow.xml
under Drawable
folder of Android resources:
<?xml version="1.0" encoding="utf-8" ?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#CABBBBBB" /> <corners android:radius="2dp" /> </shape> </item> <item android:left="0dp" android:right="0dp" android:top="0dp" android:bottom="2dp"> <shape android:shape="rectangle"> <solid android:color="@android:color/white" /> <corners android:radius="2dp" /> </shape> </item> </layer-list>
And in Android Renderer, do like this:
[assembly: ExportRenderer(typeof(MyFrame), typeof(MyAndroidRenderer))] namespace FormApp1.Droid { public class MyAndroidRenderer: FrameRenderer { Context context; public MyAndroidRenderer(Context context):base(context) { this.context = context; } protected override void OnElementChanged(ElementChangedEventArgs<Frame> e) { base.OnElementChanged(e); if (e.NewElement != null) { ViewGroup.SetBackgroundResource(Resource.Drawable.shadow); } } } }
Answers
We can create custom frame and implement the function with custom renderer on each platform .
MyFrame
Usage in xaml
iOS renderer
Android Renderer
For more details, you can refer this thread: https://stackoverflow.com/a/42527548/8187800 .
@jezh I tried but OnDraw not be called on android.
In Android platform, we need to create file
shadow.xml
underDrawable
folder of Android resources:And in Android Renderer, do like this:
@jezh I am so sad and I used skiasharp to do it
So I will not try your code but accept it.