我是Android新手,我创建了一个应用程序,并想要包含admob广告。 我的清单文件是:
<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<meta-data android:name="ADMOB_PUBLISHER_ID"
android:value="pub-1205981486869590" />
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
Main.java ------------
AdView adView = new AdView(this);
adView.setAdUnitId("ca-app-pub-1205981486869590/1687879061 ");
adView.setAdSize(AdSize.BANNER);
//LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
//layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("4d08da7768519000")
.build();
adView.loadAd(adRequest);
我不知道我错过了什么或做错了......它没有显示广告PLZ帮助我
答案 0 :(得分:0)
您必须配置布局尝试添加此
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
如果您想了解更多信息,请查看官方文档:Admob - get started