[英]AdMob Ads Not Showing
因此,我使用Play Services SDK实施了AdMob广告。 我已经完成了“书籍”的所有内容,但广告不会显示。
如果我将AdView背景设置为白色,则会显示空白区域,但不显示广告。 我正在使用Fragments,但我将AdView放在activity_main.xml
(尽管在片段中我在底部设置了60dp的边距)
这是我的onCreate
代码(包含实际代码和'测试'代码)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
drawer.openDrawer(Gravity.LEFT);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("Device_ID")
.build();
adView.loadAd(adRequest);
}
这是我的activity_main.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.MainActivity">
<RelativeLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adView" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="Unit_ID"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
我错过了什么?
我想除了你已经拥有的这个块之外:
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("Device_ID")
.build();
......你错过了这样的事情:
AdView adView = (AdView) this.findViewById(R.id.adView);
adView.loadAd(adRequest);
这是完整的图片:
在xml文件中是什么:
<com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" ads:adUnitId="your ad unit id" ads:adSize="BANNER"/>
在onCreate中是什么:
AdRequest adRequest = new AdRequest.Builder() .build(); AdView adView = (AdView) this.findViewById(R.id.adView); adView.loadAd(adRequest);
请注意上面的代码是用于生产。 您必须使用测试设备ID进行测试,以避免AdMob处罚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.