Close ad when you click the close button

0

I would like to know how to close the adview of the layout if the user clicks the "X" of the ad.

My ad code is below and I use it in the main activity_main layout:

    MobileAds.initialize(getApplicationContext(), getString(R.string.ID_APP_ADMOB));
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.SMART_BANNER);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

I use this code.

My xml is the following:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.xxx.android.MainActivity"
android:padding="0dp"
android:orientation="vertical"
android:weightSum="1"
android:background="#2c3e50">

<FrameLayout
    android:id="@+id/frameLayout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webview"
        android:visibility="invisible"/>

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="invisible"
        android:indeterminate="false" />

</FrameLayout>

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="@string/ID_ANUNCIO_BANNER">
</com.google.android.gms.ads.AdView>

  

I tried to implement this question: Disable admob ads after a click? ( In English) but I did not succeed!

Can anyone help me with this question?

    
asked by anonymous 10.11.2016 / 03:32

1 answer

2

Dude, for the X of the ad I believe you can not have control

What you can do is set an ID in the layout and manually create a button to close the ad

Example:

<LinearLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/adsContainer"
   ... />

   <Button
       android:id="@+id/closeAd"
       android:text="X"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" />

Ai declares everything in Java also, with AdView:

LinearLayout adscontainer = (LinearLayout) findViewById(R.id.adsContainer);
AdView mAdView = (AdView) findViewById(R.id.adView);
Button closeAd = (Button) findViewById(R.id.closeAd);

And then when the user clicks the closeAd button:

closeAd.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {

        adscontainer.removeView(mAdView);

     }
 });
    
10.11.2016 / 12:49