下列程式碼範例包含廣告單元 ID,可用於要求測試廣告。這類 ID 經過特別設定,可針對每項要求傳回測試廣告,而非實際廣告,因此可安心使用。
不過,在 Ad Manager 網頁介面註冊應用程式,並建立要在應用程式中使用的廣告單元 ID 後,請在開發期間明確將裝置設為測試裝置。
/21775744923/example/adaptive-banner
建立錨定自動調整橫幅廣告
以下範例會建立錨定自動調整橫幅廣告檢視區塊,並設置在畫面底部:
// Get the device safe width in density-independent pixels.intdeviceWidth=MobileAds.Utils.GetDeviceSafeWidth();// Define the anchored adaptive ad size.AdSizeadaptiveSize=AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(deviceWidth);// Create an anchored adaptive banner view.adManagerBannerView=newAdManagerBannerView("AD_UNIT_ID",adaptiveSize,AdPosition.Bottom);