[assembly: ExportRenderer(typeof(AdMobView),typeof(AdMobRenderer))]
namespace <ProjectName>.Droid
{
public class AdMobRenderer : ViewRenderer<AdMobView, Android.Gms.Ads.AdView>
{
public AdMobRenderer()
{
}
protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var ad = new AdView(Forms.Context);
ad.AdSize = AdSize.Banner;
ad.AdUnitId = Consts.BANNER_ID_ANDROID_BOTTOM;
ad.AdListener = new MyAdListener(adViewRef);
ad.LoadAd((new AdRequest.Builder()).Build());
SetNativeControl(ad);
}
}
}
class MyAdListener : AdListener
{
public CMyAdListener(View refToView)
{
adViewRef = refToView;
}
public override void OnAdFailedToLoad(int errorCode)
{
Debug.WriteLine("error: " + errorCode.ToString());
base.OnAdFailedToLoad(errorCode);
}
public override void OnAdClosed()
{
base.OnAdClosed();
}
public override void OnAdLeftApplication()
{
base.OnAdLeftApplication();
}
public override void OnAdLoaded()
{
base.OnAdLoaded();
}
public override void OnAdOpened()
{
base.OnAdOpened();
}
}
}