【问题标题】:Android - How to Dynamically set AdMob advertiser ID or ad size?Android - 如何动态设置 AdMob 广告客户 ID 或广告尺寸?
【发布时间】:2016-07-05 22:07:28
【问题描述】:

https://firebase.google.com/docs/admob/android/banner 中提供的示例代码在 xml 文件中使用给定的广告商 ID 和广告尺寸对我来说效果很好。但对我来说,能够根据某些参数设置广告客户 ID 和横幅尺寸非常重要。

我考虑过这两个,但它们对我不起作用 ->

Programatically set the AdMob id String

How to specify adUnitId programmatically for AdMob?

当我尝试实现第二个时,当我尝试将 java 文件链接到 xml 文件时出现错误。它们应该如何关联?

【问题讨论】:

  • 请发布您的代码。 @ARIPOVULA

标签: android admob


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:background="@null"
        android:layout_height="wrap_content" />
</LinearLayout>

AdView mAdView = new AdView(context);
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdUnitId(AD_UNIT_ID);
FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.adView);
frameLayout.addView(mAdView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 2016-03-02
    • 2019-09-17
    • 1970-01-01
    • 2023-03-16
    相关资源
    最近更新 更多