AdMob in a fragment

前端 未结 2 1032
孤城傲影
孤城傲影 2021-01-03 12:38

I\'m inserting an AdMob in my application. but I have a problem about it.

when I inserted some codes about it in Eclipse, I can see an error message about \"the con

相关标签:
2条回答
  • 2021-01-03 12:52

    Change your layout in this way:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <com.google.android.ads.AdView
            android:id="@+id/fragment_03_admob"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:adSize="BANNER"
            app:adUnitId="@string/activity_admobID"
            app:loadAdOnCreate="true"
            app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
    
    </LinearLayout>
    

    You was using a wrong namespace declaration.

    0 讨论(0)
  • 2021-01-03 13:01

    You have to write root before the findViewById:

    AdView mAdView = (AdView) root.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    
    0 讨论(0)
提交回复
热议问题