1

I am new in android app development and I am creating an app in android studio, which has 2 activities. One is activity_main.xml which has a button to open second activity. When I set the banner ad it shows only on bottom of activity_main.xml and I want to set same banner ad in my second activity. What should I do. Please help me.thanks!!

4

2 回答 2

0

您需要将广告横幅视图复制activity_main.xml到第二个活动的布局。

另外,请在您的问题中包含代码,因为它使人们更容易帮助您!

于 2017-07-06T02:10:44.960 回答
0

通过继承类创建一个超FirstActivity类。从子类的方法调用。SecondActivityActivityintegrateAdView()onCreate()

integrateAdView()超类方法:

public void integrateAdView(){ 

    layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setGravity(android.view.Gravity.BOTTOM | android.view.Gravity.CENTER_HORIZONTAL);   
    addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));

    adView = new AdView(this, AdSize.BANNER, ADV_PUB_ID);
    adView.setAdListener(new AdListener(){
       ...
    });
    layout.addView(adView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    AdRequest request = new AdRequest();    
    request.addTestDevice(AdRequest.TEST_EMULATOR);
    adView.loadAd(request);   
}
于 2017-07-06T11:43:36.487 回答