Android Admob:AdviewXML来自哪里?
我已经学习了一些教程/stackoverflow线程,学习如何将Android Admob:AdviewXML来自哪里?,android,admob,Android,Admob,我已经学习了一些教程/stackoverflow线程,学习如何将Admob横幅添加到我的UI底部 我已将adMob sdk添加到库中,并将以下内容添加到要在其上显示广告的UI的XML中 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:ads="
Admob
横幅添加到我的UI底部
我已将adMob sdk添加到库中,并将以下内容添加到要在其上显示广告的UI的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"/>
我的问题是,我没有称为
“adView”
的xml。我尝试过几种不同版本的Java代码(每个教程都有点不同),但都会导致类似的Java错误。我缺少什么?您缺少包含adView的Admob库。请添加该库
是如何将Admob添加到应用程序的完整教程
希望它能有所帮助。您没有任何
R.id.adView
(至少在粘贴的代码中),您必须使用R.id.adMob
,因为这是视图的id。
您必须将其添加到布局文件中:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
如果在build.gradle中使用productFlavors,请确保在productFlavors块中添加“com.google.android.gms:play services ads:7.5.0”依赖项,而不是一般依赖项块
productFlavors {
free {
...
dependencies {
compile 'com.google.android.gms:play-services-ads:7.5.0'
}
}
full {
...
}
}
productFlavors {
free {
...
dependencies {
compile 'com.google.android.gms:play-services-ads:7.5.0'
}
}
full {
...
}
}