开发者

Integrating Admob in Android

开发者 https://www.devze.com 2023-03-05 22:54 出处:网络
I am integrating AdMob into my android application. I have followed the directions on the admob site to a T.In my attrs.xml I have the following.

I am integrating AdMob into my android application.

I have followed the directions on the admob site to a T.In my attrs.xml I have the following.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="com.google.ads.AdView">
        <attr name="adSize">
            <enum name="BANNER" value="1" />
            <enum name="IAB_MRECT" value="2" />
            <enum name="IAB_BANNER" value="3" />
            <enum name="IAB_LEADERBOARD" value="4" />
        </attr>
        <attr name="adUnitId" format="string" />
    </declare-styleable>
</resources>

And I setup the View in my main.xml

 <com.google.ads.AdView android:id="@+id/adView"
                               android:layout_width="wrap_content"
                               android:layout_height="wrap_content"
                               ads:adUnitId="MYID"
                               ads:adSize="BANNER" /
开发者_运维问答

>

When viewing the main.xml in Graphical Layout it is giving an error on the AdView

Adview missing required XML Attribute "adSize"

Wondering if I have done something wrong?


See if this will help you.


To expand on rochdev's answer:

There are some changes to the way Admob works in version 4.1.0. There's a discussion on Google Groups about this issue and how they haven't updated the documentation.

Google employee Tim posted:

1) Remove attrs.xml (or if you need it for your own custom attributes, remove the parts related to AdViews).

2) Change the namespace in your layout from xmlns:ads="http://schemas.android.com/apk/res/com.your.packagename" to xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

Once you have made those two changes, you should now see an ad.

If that doesn't fix it, try following the example on this page. This question may be helpful.

0

精彩评论

暂无评论...
验证码 换一张
取 消