2012-03-09 48 views
0

我可以將廣告投放到我的應用主要活動中。 但我無法弄清楚如何讓它在我的應用程序中的所有三個活動中顯示。如何在活動中顯示admob廣告

+0

的每個活動做同樣的。 – asish 2012-03-09 05:35:37

回答

2
import com.google.ads.*; 


    public class testActivity extends Activity { 
      private static final String MY_AD_UNIT_ID = "yourId"; 
      private AdView adView; 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      super.loadUrl("file:///android_asset/www/index.html");   
     // Create the adView 
        adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID); 
        LinearLayout layout = super.root; // this is the only change 
        layout.addView(adView); 
        adView.loadAd(new AdRequest()); 


    Xml File: 
     <com.admob.android.ads.AdView 
       android:id="@+id/ad" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       xmlns:backgroundColor="#000000" 
       xmlns:primaryTextColor="#ffffff" 
       xmlns:secondaryTextColor="#cccccc" 
0

您是否將標籤包含在所有佈局中。

<com.admob.android.ads.AdView 
     android:id="@+id/ad" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     xmlns:backgroundColor="#000000" 
     xmlns:primaryTextColor="#ffffff" 
     xmlns:secondaryTextColor="#cccccc" 
    />