【发布时间】:2013-11-16 07:15:31
【问题描述】:
我正在尝试在动态壁纸的设置页面中添加广告横幅,但尽管我多次尝试无法添加广告。我遵循了许多教程,但都没有。请告诉我我做错了什么。
我遵循了这个教程
http://irinaramazova.blogspot.in/2011/09/add-admob-adview-to-preferenceactivity.html
我也看到了这个有用的
How do I put an admob adview in the settings screen for a live wallpaper?
两者都不起作用。 我的代码如下
我的 Admobpreference 类
public class AdmobPreference extends Preference
{
public AdmobPreference(Context context) {
super(context, null);
}
public AdmobPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View onCreateView(ViewGroup parent) {
//override here to return the admob ad instead of a regular preference display
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return inflater.inflate(R.layout.admob_preference, null);
}
}
admobpreference.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.djcharon.valentinesday"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent" android:layout_height="fill_parent"
>
<com.google.ads.adview android:id="@+id/adView" android:layout_width="fill_parent" android:layout_height="wrap_content" ads:adunitid="myid" ads:adsize="BANNER" >
</com.google.ads.adview>
</LinearLayout>
我的 activity_preference.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<com.djcharon.valentinesday.AdmobPreference android:key="adView" />
<CheckBoxPreference android:key="touch" android:title="Enable Touch" android:defaultValue="true"></CheckBoxPreference>
<ListPreference android:key="kiss" android:title="Wallpaper" android:summary="Select the Wallpaper" android:defaultValue="Background 1" android:entries="@array/listKissSound" android:entryValues="@array/listKissSound" ></ListPreference>
<ListPreference android:key="heartLife" android:title="Particle life" android:summary="The Particle lifecicle." android:defaultValue="20" android:entries="@array/listLifeCicle" android:entryValues="@array/listLifeCicle" ></ListPreference>
</PreferenceScreen>
我在清单中添加了活动
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
</activity>
我收到一个错误
com.google.ads.adView 膨胀错误
【问题讨论】:
-
你添加了google ads的jar文件吗?
-
我添加了 jar 并且我还查看了上面给出的两个链接,说我的是重复的。当我使用上述链接中的建议时,错误消失了,但是当按下设置按钮时我的应用程序崩溃了。
-
请按照我的示例更改您的 xml 和首选项活动。
标签: android settings admob ads live-wallpaper