正确禁用AdMob的广告 [英] Correctly disable AdMob ads

查看:595
本文介绍了正确禁用AdMob的广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我AdMob的整合到我的应用程序,我不知道如何正确地禁用广告。我想给用户禁用它们的能力。我不想得到,因为错误的即时通讯pressions与AdMob的任何问题。这是正确的方式还是我应该考虑些什么呢?

  AD浏览报广告=(AD浏览报)findViewById(R.id.ad);
ads.setEnabled(假);
 

解决方案

在您的布局文件(例如,main.xml中):

 <的LinearLayout
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / adsContainer>

    < com.admob.android.ads.AdView
        机器人:ID =@ + ID / admobAds
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        应用:的backgroundColor =#000000
        应用程序:primaryTextColor =#FFFFFF
        应用程序:secondaryTextColor =#CCCCCC>

< / LinearLayout中>
 

然后在你的code(例如,在一个如果块)

 (LinearLayout中)adscontainer =(的LinearLayout)findViewById(R.id.adsContainer);

查看admobAds =(查看)findViewById(R.id.admobAds);

adscontainer.removeView(admobAds);
 

此将永久(对于该应用的生命周期)从辣油,这意味着将不会有任何的广告上删除广告请求的

I am integrating AdMob into my app and I wonder how to disable Ads correctly. I want to give the user the ability to disable them. I don't want to get any problems with AdMob because of wrong impressions. Is this way correct or should I consider something?

AdView ads = (AdView) findViewById(R.id.ad);
ads.setEnabled(false);

解决方案

In your layout file (eg, main.xml) :

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/adsContainer">

    <com.admob.android.ads.AdView 
        android:id="@+id/admobAds" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        app:backgroundColor="#000000" 
        app:primaryTextColor="#FFFFFF" 
        app:secondaryTextColor="#CCCCCC">

</LinearLayout>

Then in your code (eg, inside a "if" block)

(LinearLayout) adscontainer = (LinearLayout) findViewById(R.id.adsContainer);

View admobAds = (View) findViewById(R.id.admobAds);

adscontainer.removeView(admobAds);

This will "permanently" (for the lifecycle of the app) remove the ads from the layou, which means that there will not be any ads requested.

这篇关于正确禁用AdMob的广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆