To.vi
To.vi

Reputation: 43

How to disable AdMob on a page

How can you disable admob on a page: this is how i implemented it in XML and main activity (of course i have string with Ad-id:

XML below:

   <LinearLayout
    android:layout_alignParentBottom="true"
    android:id="@+id/AdsArea"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical">
</LinearLayout>

Main activity below:

  private void loadGoogleAds() {
        LinearLayout rootLayout = (LinearLayout) findViewById(R.id.AdsArea);
        AdView adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.ad_unit_id));
        rootLayout.addView(adView, 0);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

Upvotes: 1

Views: 469

Answers (1)

Ferdous Ahamed
Ferdous Ahamed

Reputation: 21766

As you are adding AdView programatically, I think to remove ads don't call loadGoogleAds() from your Activity.

OR, you can hide AdView using:

if (adView.getVisibility() == AdView.VISIBLE)
    adView.setVisibility(View.GONE);

OR, remove adView from rootLayout using:

rootLayout.removeViewAt(0); 

Upvotes: 1

Related Questions