Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide/disable admob adview?

I hide admob adview by view.gone:

//adView.setClickable(false);
//adView.clearFocus();
//adView.setEnabled(false);
//adView.setFilterTouchesWhenObscured(true);
//adView.setFocusable(false);
//adView.setFocusableInTouchMode(false);
adView.setVisibility(View.GONE);
adView.startAnimation( animation );

This hides the ad, but the adview itself is still touchable, so if I touch the adview's space, it still opens the browser and redirects me to the ad, although the ad itself is not visible.

How to disable the touch event too? I've tried all lines above but none of them worked.

Any advice?

like image 575
Tamas Avatar asked Apr 22 '12 22:04

Tamas


People also ask

Why did my ads stop showing AdMob?

Ads won't show if you haven't integrated the Google Mobile Ads SDK correctly. Is your ad implementation code working properly? Test your implementation code to check that ads can show. You can also use ad inspector to test your app's ad serving.


2 Answers

Setting adView.setVisibility(View.GONE) and removing the AdMob view from the view hierarchy will hide the ad and prevent user interaction in most cases.

Don't forget to end the AdView lifecycle when the Activity displaying the ad is finished (destroyed). From the AdMob SDK Javadoc:

public void destroy()

Destroys the AdView. The AdView should no longer be used after this method is called.

Make a call to destroy() in the Activity's onDestroy() callback:

@Override
public void onDestroy() {
    if (adView != null) {
        adView.destroy();
    }
super.onDestroy();
}
like image 53
mjama Avatar answered Sep 28 '22 03:09

mjama


Try to use setOnTouchListener and Override onTouch like you want. Also you can use removeView():

LinearLayout linLay = (LinearLayout)findViewById(R.id.ad_layout);
linLay.removeView(adView); 
LinearLayout.LayoutParams params = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
linLay.addView(adView, params);

and add it back when you need.

like image 33
jumper0k Avatar answered Sep 28 '22 02:09

jumper0k