我需要在java类中以编程方式设置admob横幅广告单元id。
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
mAdView.setAdSize(AdSize.SMART_BANNER);同时使用xml进行布局
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>我试过了,但不起作用,因为它显示了一个错误:Required XML attribute “adSize” was missing
请帮帮忙
发布于 2018-05-11 11:54:09
尝尝这个
将其放到onCreate上:
mAdView = (AdView) findViewById(R.id.adView);
adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mAdView.loadAd(adRequest);放入Xml
<com.google.android.gms.ads.AdView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="@string/BANNER_ID" />放入字符串文件
<string name="BANNER_ID">Your Banner Id</string>https://stackoverflow.com/questions/50284154
复制相似问题