【发布时间】:2013-04-14 23:18:13
【问题描述】:
我是 Ads 新手,并且能够在我的布局中使用以下代码在我的 Android 应用中成功添加我的第一个广告。
mylayout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
由于我的应用中有多个布局,我将常见的 AdView 属性(例如 adSize、adUnitId 等)移动到了 styles.xml 以减少代码大小。但是,在此更改之后,我遇到了类似的错误
error: Error: No resource found that matches the given name: attr 'ads:adUnitId'.
error: Error: No resource found that matches the given name: attr 'ads:adSize'.
error: Error: No resource found that matches the given name: attr 'ads:loadAdOnCreate'.
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" >
<style name="MyAdView">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="ads:adSize">BANNER</item>
<item name="ads:adUnitId">xxx</item>
<item name="ads:loadAdOnCreate">true</item>
</style>
</resources>
android:xxx 标签没有问题,问题似乎只出在 ads:xxx 上。为了使用 com.google.ads 命名空间,我还应该做些什么。 由于当我在布局中有代码时一切正常,我想我拥有在我的应用程序中添加广告所需的一切(AdMob SDK、构建路径中的 admob 库以及订单和导出等)。 请建议。提前致谢。
【问题讨论】: