2011-09-16 82 views
0

就像在螢火蟲動態壁紙(http://www.livewallpapers.org/fireflies-free-1543/)中,我不知道如何在預覽屏幕(不是設置屏幕)中放置廣告橫幅。如何將廣告橫幅放置在動態壁紙的預覽屏幕中?

附加信息:當我在Android 2.2.1的HTC上安裝Fireflies壁紙時,該橫幅顯示在預覽和設置屏幕上,但在我的另外兩個索尼愛立信上(2.3.3上),我只能請參閱設置屏幕中的橫幅。這是否與索尼愛立信或Android版本有關?

謝謝。

PS我沒有看這個鏈接,但發現沒有回答我的問題:

How do I put an admob adview in the settings screen for a live wallpaper?

+0

回覆:您的附加信息:有可能廣告沒有出現,因爲他們只是沒有廣告來展示,而不是電話之間的差異。我一直在使用admob,只有約70-80%的請求實際上導致了廣告顯示(填充率%),否則廣告視圖就不會出現。不知道這是否有幫助:) – Jay

回答

0

創建一個新類AdPreference.java和包括此代碼:

public class AdPreference extends Preference { 

    public AdPreference(Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);} 
    public AdPreference(Context context, AttributeSet attrs) {super(context, attrs);} 
    public AdPreference(Context context) {super(context);} 

    @Override 
    protected View onCreateView(ViewGroup parent) { 
     // this will create the linear layout defined in ads_layout.xml 
     View view = super.onCreateView(parent); 

     // the context is a PreferenceActivity 
     Activity activity = (Activity)getContext(); 

     // Create the adView 
     AdView adView = new AdView(activity, AdSize.BANNER, "YOUR_ADMOB_ID_HERE"); 

     ((LinearLayout)view).addView(adView); 

     // Initiate a generic request to load it with an ad 
     AdRequest request = new AdRequest(); 
     adView.loadAd(request);  

     return view;  
    } 
} 

在你的資源/ layout文件夾創建一個名爲ad_layout.xml的新xml佈局必須精確。然後包括此代碼:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
</LinearLayout> 

然後在你的 「設置」 XML中的xmlns行之後添加此權:

<com.yourpackagename.AdPreference android:layout="@layout/ad_layout"/> 

在AndroidManifest.xml中前

<activity android:name="com.google.ads.AdActivity" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

<meta-data android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" android:value="false" /> 

同時添加這將其添加到您的清單中:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.INTERNET"/> 

就是這樣。它會很好地工作。