【问题标题】:Admob AdView not working showing adsAdmob AdView 无法显示广告
【发布时间】:2017-11-23 10:19:04
【问题描述】:

您好,当我将 sqlite 数据库中的数据加载到应用程序中时,我的应用程序没有显示 admob 横幅广告,这是我的代码。你能帮忙吗?我正在使用 admobs 测试广告单元 id 。我还在清单中授予了权限。我正在使用最新的 Google 广告库。 主要活动.java

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);



        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);


        recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
        recyclerView.setHasFixedSize(true);
        db= new DatabaseHelper(this);
        searchView = (SearchView) findViewById(R.id.searchView);
        searchView.setQueryHint("Search Here");
        searchView.setQueryRefinementEnabled(true);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        data = new ArrayList<DictObjectModel>();
        fetchData();

        // Banner Ads

        mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);


        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {return  false; }

Content_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent" android:paddingLeft="10dp"
   android:paddingRight="10dp"
   android:paddingTop="10dp"
   android:background="#ededed"
   android:paddingBottom="10dp">


    <android.support.v7.widget.SearchView
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:id="@+id/searchView"/>

    <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/searchView"
       android:descendantFocusability="blocksDescendants"
       android:scrollbars="vertical"/>

    <com.google.android.gms.ads.AdView
       xmlns:ads="http://schemas.android.com/apk/res-auto"
       android:id="@+id/adView"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
       android:layout_alignParentBottom="true"
       ads:adSize="SMART_BANNER"
       ads:adUnitId="@string/banner">
    </com.google.android.gms.ads.AdView>


</RelativeLayout>

谢谢

【问题讨论】:

  • 尝试在请求中添加TestDevice("TEST_DEVICE_ID")

标签: android android-recyclerview admob ads android-cardview


【解决方案1】:

如果要使用ads:adSize="SMART_BANNER",则必须将android:layout_width设置为match_parent。否则,您可以使用ads:adSize="BANNER"

【讨论】:

    【解决方案2】:

    添加这个看看有没有错误。

    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
    
        }
    
        @Override
        public void onAdFailedToLoad(int errorCode) {
           ..  print the error code to see if there is one
        }
    
        @Override
        public void onAdOpened() {
    
        }
    
        @Override
        public void onAdLeftApplication() {
        }
    
        @Override
        public void onAdClosed() {
    
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多