2010-08-31 132 views
2

所以我試圖用admob將一個簡單的廣告添加到我的應用中。我跟着SDK的教程,但遇到了一個錯誤。Android - Admob問題!

這裏的錯誤:

Multiple annotations found at this line: 
- ERROR No resource identifier found for attribute 'secondaryTextColor' in package 
'man.utd.headlines.man.utd' 
- ERROR No resource identifier found for attribute 'primaryTextColor' in package 'man.utd.headlines.man.utd' 
- ERROR No resource identifier found for attribute 'backgroundColor' in package 'man.utd.headlines.man.utd' 

所以我想,這一定是我的包名稱的問題,但據我所看到的一切都OK。

在我的佈局文件我有以下幾點:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines.man.utd" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

但包的名稱似乎是正確的:

package man.utd.headlines.man.utd; 

任何想法?這非常令人沮喪!

我也檢查了我的表現,並與這個包的名字都試過,但它仍然不能正常工作:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="man.utd.headlines" 

任何幫助是極大的讚賞。

更新:通過更改軟件包名稱來解決,使它們更加一致 - 它們在主類和清單中完全一樣!

新問題:廣告不會顯示!

繼承人我佈局文件:

<?xml version="1.0" encoding="utf-8"?> 

<WebView 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 

<com.admob.android.ads.AdView 
    android:id="@+id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
    myapp:backgroundColor="#000000" 
    myapp:primaryTextColor="#FFFFFF" 
    myapp:secondaryTextColor="#CCCCCC" /> 

任何想法?任何幫助非常感謝:)。

回答

4

貴attrs.xml(在res /值文件夾)的文件是這樣的:

<?xml version="1.0" encoding="utf-8" ?> 
    <resources> 
     <declare-styleable name="com.admob.android.ads.AdView"> 
     <attr name="backgroundColor" format="color" /> 
     <attr name="primaryTextColor" format="color" /> 
     <attr name="secondaryTextColor" format="color" /> 
     <attr name="keywords" format="string" /> 
     <attr name="refreshInterval" format="integer" /> 
     </declare-styleable> 
    </resources> 

如果沒有,創建一個XML文件的名稱在資源attrs.xml /值文件夾,這個代碼複製到它。

+0

感謝您的答覆,我解決了這個問題,但有一個新的,看看編輯!任何幫助是極大的讚賞。 – user319940 2010-08-31 23:12:15

+0

我需要這個排序儘快,如果有人可以聘請糾正這一點,那麼我不介意花費少量的$$來得到這個工作。 – user319940 2010-09-01 00:00:42

+0

將android:layout_height =「100px」 更改爲android:layout_height =「wrap_content」 並查看是否有效 – magicman 2010-09-02 02:12:56

2

對於新版本的谷歌現在AdMob的attrs.xml文件應該是這樣的:

<?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"/> 
     <attr name="backgroundColor" format="color" /> 
     <attr name="primaryTextColor" format="color" /> 
     <attr name="secondaryTextColor" format="color" /> 
     <attr name="keywords" format="string" /> 
     <attr name="refreshInterval" format="integer" /> 
    </declare-styleable> 
</resources>