我正在将 AdMob 集成到我的应用中,我想知道如何正确禁用广告。我想让用户能够禁用它们。我不想因为错误的印象而在 AdMob 上遇到任何问题。这种方式正确还是我应该考虑一下?
AdView ads = (AdView) findViewById(R.id.ad);
ads.setEnabled(false);
最佳答案
在您的布局文件(例如 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>
然后在您的代码中(例如,在“if” block 内)
(LinearLayout) adscontainer = (LinearLayout) findViewById(R.id.adsContainer);
View admobAds = (View) findViewById(R.id.admobAds);
adscontainer.removeView(admobAds);
这将“永久”(在应用的生命周期内)从布局中移除广告,这意味着不会有任何广告请求。
关于android - 正确禁用 AdMob 广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4549401/