looks good , but what if your app is having so many activities and you want to put banner on all those.

possibe solutions

1) create banner in all activity xml layouts and use above steps for all activities. Doesn’t seems impressive. huhhh…

2) Have some solution which bring banner working with less efforts. Let’s try with android.R.id.contentIt’s a root view [FrameLayout] of all activities in android app. So we can add banner to this view.

Create Following method in your BaseActivity which is the base for all your activities.

@SuppressLint("NewApi")protectedvoidsetupAdAtBottom(){content=(FrameLayout)findViewById(android.R.id.content);// inflate ad layout and set it to bottom by layouparamsfinalLinearLayoutad=(LinearLayout)getLayoutInflater().inflate(R.layout.ad_layout,null);FrameLayout.LayoutParamsparams=newFrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);params.gravity=Gravity.BOTTOM;ad.setLayoutParams(params);// adding viewtreeobserver to get height of ad layout , so that// android.R.id.content will set margin of that heightViewTreeObservervto=ad.getViewTreeObserver();vto.addOnGlobalLayoutListener(newOnGlobalLayoutListener(){@OverridepublicvoidonGlobalLayout(){if(Build.VERSION.SDK_INT<16){ad.getViewTreeObserver().removeGlobalOnLayoutListener(this);}else{ad.getViewTreeObserver().removeOnGlobalLayoutListener(this);}intwidth=ad.getMeasuredWidth();intheight=ad.getMeasuredHeight();Log.i("ad hight",height+"");setSpaceForAd(height);}});addLayoutToContent(ad);}privatevoidsetSpaceForAd(intheight){// content.getChildAt(0).setPadding(0, 0, 0, 50);Viewchild0=content.getChildAt(0);FrameLayout.LayoutParamslayoutparams=(android.widget.FrameLayout.LayoutParams)child0.getLayoutParams();layoutparams.bottomMargin=height;child0.setLayoutParams(layoutparams);}privatevoidaddLayoutToContent(Viewad){// content.addView(ad);content.addView(ad);AdViewmAdView=(AdView)ad.findViewById(R.id.adView);AdRequestadRequest=newAdRequest.Builder().build();mAdView.loadAd(adRequest);}

What this method setupAdAtBottom is doing is inflating ad_layout and add it to bottom of android.R.id.content.

So now call setupAdAtBottom() after setcontentView of your activity. And Hulla… You are done. A single line will do the rest work and it will not affect your original layout.