Close ad by clicking the close button
I would like to know how do I close the layout adview if the user clicks on the "X" of the ad.
My ad code is the one below and I use in the main layout activity_main :
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 as follows:
<?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?
0
Author: Comunidade, 2016-11-10
1 answers
Man, by the X of the ad I believe you can't 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 too, along with AdView:
LinearLayout adscontainer = (LinearLayout) findViewById(R.id.adsContainer);
AdView mAdView = (AdView) findViewById(R.id.adView);
Button closeAd = (Button) findViewById(R.id.closeAd);
And ai when the user clicks the closeAd button:
closeAd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adscontainer.removeView(mAdView);
}
});
1
Author: Leonardo Dias, 2016-11-10 11:49:07