我是新手,刚学习广告,使用以下代码在我的布局中成功地添加了第一个广告。
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、构建路径和顺序和导出等)。 请给予建议。提前致谢。
jar
ж–Ү件дёҚеҢ…еҗ«еёҰжңүиө„жәҗзҡ„XML
ж–Ү件пјҢеӣ жӯӨжӮЁж— жі•еј•з”Ёе®ғ们пјҡжӮЁжІЎжңүеҸҜз”Ёзҡ„ads.Rе‘ҪеҗҚз©әй—ҙгҖӮ - gipicom.google.ads.AdView
包含在jar
中,但由于它不是一个合适的 Android 库,所以你无法在 styles.xml 中访问或引用其命名空间。我希望能被反驳。 - gipi