对不起,我非常喜欢admob,我把它放在另一个简单的应用程序中,但我无法在livewallpaper中得到它。我得到一个com.google.android.gms.ads.adView无法强制转换为android.preference.Preference
这是我的livewallpaper_settings.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:key="livewallpaper_settings"
android:title="@string/livewallpaper_settings" >
<ListPreference
android:entries="@array/livewallpaper_testpattern_names"
android:entryValues="@array/livewallpaper_testpattern_prefix"
android:key="livewallpaper_testpattern"
android:summary="@string/livewallpaper_settings_summary"
android:title="@string/livewallpaper_settings_title" />
<CheckBoxPreference
android:key="livewallpaper_movement"
android:summary="@string/livewallpaper_movement_summary"
android:summaryOff="Still test pattern"
android:summaryOn="Moving test pattern"
android:title="@string/livewallpaper_movement_title" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" />
</PreferenceScreen>
这是我的LiveWallpaperSettings.java:
package ca.jvsh.livewallpaper;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class LiveWallpaperSettings extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
getPreferenceManager().setSharedPreferencesName(LiveWallpaper.SHARED_PREFS_NAME);
addPreferencesFromResource(R.xml.livewallpaper_settings);
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
getPreferenceManager().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onDestroy() {
getPreferenceManager().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {}
}
答案 0 :(得分:0)
除了PreferenceScreen中的“首选项”之外,您不能拥有任何类型的视图。 AdView不是首选项。
此外,您的用户是否真的会在偏好设置屏幕上将您的所有时间花在您的应用中?