Admob广告未在Android回收器视图中展示 [英] Admob ads not showing in Android recycler view

查看:56
本文介绍了Admob广告未在Android回收器视图中展示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我的应用程序未在Android回收站视图中显示广告,我想在应用程序底部显示广告,但未显示它们,我不想显示原生广告,我只想显示一个横幅在底部。这是一个字典应用程序,它使用Sqlite数据库加载本机广告不适合的数据。你能帮忙吗,这是我的代码。
主要活动。java

Hi there my app is not showing ads in Android recycler view I want to show the ads at the bottom of my app but it is not displaying them I don't want to show native ads I only want to show a single banner at the bottom. It is a dictionary app which uses Sqlite database to load data native ads will not suit it. Can u please help here is my code. Main activity.java

mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        Toast.makeText(getApplicationContext(), "onAdFailedToLoad", Toast.LENGTH_LONG).show();
            if (mAdView.getVisibility() == View.GONE) {
                mAdView.setVisibility(View.VISIBLE);
            }
        }
        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(getApplicationContext(), "onAdFailedToLoad", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onAdOpened() {
            Toast.makeText(getApplicationContext(), "onAdOpened", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onAdLeftApplication() {
            Toast.makeText(getApplicationContext(), "onAdLeftApplication", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onAdClosed() {
            Toast.makeText(getApplicationContext(), "onAdClosed", Toast.LENGTH_SHORT).show();
        }
    });


    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

这是我的内容main.xml

And here is my content main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#e2e2e2"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/adView"
        android:descendantFocusability="blocksDescendants"
        android:scrollbars="vertical"/>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111"/>
</RelativeLayout>


推荐答案

在OnCreate上添加

MobileAds.initialize(this,"Your ad unit id from admob");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice("Add Your Device id").build();
mAdView.loadAd(adRequest);

替代方法

@Override
public void onPause() {
    if (mAdView != null) {
         mAdView.pause();
    }
    super.onPause();
}

@Override
public void onResume() {
    super.onResume();
    if (mAdView != null) {
         mAdView.resume();
    }
}

@Override
public void onDestroy() {
    if (mAdView != null) {
         mAdView.destroy();
    }
    super.onDestroy();
}

您的XML文件

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_home_footer" />

这篇关于Admob广告未在Android回收器视图中展示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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