0

我有问题我想将 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 插件。 那么问题出在哪里?

4

2 回答 2

0

您可能没有广告来填充 Admob,您在 LogCat 中收到什么?

于 2011-12-04T13:58:07.003 回答
0

我建议您在hierarchyviewer工具中检查您的视图。您应该能够看到您的视图是否被添加到您的 LinearLayout 中。有时添加了一个视图,但布局参数不正确,因此视图不可见。

您可以在 \tools 中找到查看器。只需在模拟器中启动您的应用程序,切换到命令提示符/终端并执行可执行文件。

于 2011-12-04T14:09:41.810 回答