How to hide/disable admob adview?

后端 未结 3 1709
暖寄归人
暖寄归人 2021-02-09 16:13

I hide admob adview by view.gone:

//adView.setClickable(false);
//adView.clearFocus();
//adView.setEnabled(false);
//adView.setFilterTouchesWhenObscured(true);
/         


        
相关标签:
3条回答
  • 2021-02-09 16:59

    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.

    0 讨论(0)
  • 2021-02-09 17:12

    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();
    }
    
    0 讨论(0)
  • 2021-02-09 17:13
    final com.google.ads.AdView ad = (AdView) findViewById(R.id.rect_ad);
       if ( ad != null) {
                ad.stopLoading();
                ad.destroy();
                getWindowManager().removeView(ad);
       }
    

    even this code doesn't destroy AdMob =((( I have it's Handler and WebView in memory holding my activity

    0 讨论(0)
提交回复
热议问题