我有问题我想将 admob 添加到 Preference Activity,但应用程序没有显示它。
这是我的 AdMob 活动:
public class AdMobActivity extends Preference {
public AdMobActivity(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}
public AdMobActivity(Context context, AttributeSet attrs) {super(context, attrs);}
public AdMobActivity(Context context) {super(context);}
@Override
protected View onCreateView(ViewGroup parent) {
// this will create the linear layout defined in
View view = super.onCreateView(parent);
// the context is a PreferenceActivity
Activity activity = (Activity)getContext();
// Create the adView
AdView adView = new AdView(activity, AdSize.BANNER, "XXXXXXXXXXX");
((LinearLayout)view).addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
adView.loadAd(request);
return view;
}
}
这是我的 AdMob (banner.xml) 布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
这是我的偏好活动的 xml:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Ads">
<com.blabla.asafgasf.AdMobActivity android:layout="@layout/banner"/>
</PreferenceCategory>
<PreferenceCategory
.....
</PreferenceCategory>
</PreferenceScreen>
我已经target=android-13
在 project.properties 和我的清单中设置了:
<activity android:name=".AdMobActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
如果我|screenLayout|uiMode|screenSize|smallestScreenSize
从我的应用程序中的 configChanges 中删除,将出现红色框并写有:您必须在 AndroidManifest.xml 中使用 configChanges 声明 AdActivity。
我已经安装了最新版本的 AdMob 库 (4.3.1) 和最新版本的 SDK (API 14) 和最新的 ADT 插件。 那么问题出在哪里?