如何在各种活动中显示admob广告

时间:2012-03-09 03:27:38

标签: android admob

我可以将广告投放到我的应用主要活动中。 但我无法弄清楚如何在我的应用程序中的所有三项活动中显示它。

2 个答案:

答案 0 :(得分: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"

答案 1 :(得分: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"
    />
相关问题