我遵循了一些教程/ stackoverflow线程,以学习如何在UI底部添加Admob
标语。
我已将adMob sdk添加到库中,并将以下内容添加到要在其上展示广告的用户界面的XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000">
<com.google.ads.AdView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/adMob"
android:layout_alignParentBottom="true"
ads:adUnitId="YOUR AdMob publisher ID"
ads:adSize="BANNER"/>
然后,将以下内容添加到该UI的Java代码中
AdView adview = (AdView)findViewById(R.id.adView);
AdRequest re = new AdRequest();
re.setTesting(true);
adview.loadAd(re);
我的问题是我没有名为
"adView"
的xml。我尝试了几种不同版本的Java代码(每个教程都有些不同),但是所有这些都会导致类似的Java错误。我想念什么? 最佳答案
您没有任何R.id.adView
(至少在粘贴的代码中),必须使用R.id.adMob
,因为这是视图的ID。
您必须将此添加到您的布局文件:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"