我尝试了来自全世界的所有代码,我得到了两件事:1)错误或2)不要看广告..
这是我的清单:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.adview.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
的修订!!!! 的 **这是我的 NEW 布局:**
<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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/hello_world" />
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adUnitId="xxxxxxxx" i put my editor id here..
ads:loadAdOnCreate="true"
ads:adSize="BANNER"/>
</RelativeLayout>
和... 这是我的班级(我没有放任何东西,因为我在布局中做了)
package com.example.adview;
import android.os.Bundle;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import android.app.Activity;
import android.view.Menu;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我将GoogleAdMobAdsSdk-6.4.1(最新版本)放在libs和Project&gt; RightClick&gt;属性&gt; JavaBuildPath&gt; AddExternalJARs&gt; GoogleAdMobAdsSdk-6.4.1
答案 0 :(得分:0)
是否添加了此
xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads"
例如
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
您必须在广告代码中添加tihs行
ads:loadAdOnCreate="true"
答案 1 :(得分:0)
您需要将此添加到AdView
ads:loadAdOnCreate="true"
或者您需要以编程方式从您的活动中加载您的添加内容(我在onCreate中建议)。
final AdView adView = findViewById(R.id.adView);
adView.load(new AdRequest());
答案 2 :(得分:0)
jq