2015-05-01 82 views
2

我试图在我的应用程序中添加AdMob广告。在包中找不到属性adSize的资源标识符

在清单中,我有:

<uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

<meta-data android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" /> 


<activity android:name="com.google.android.gms.ads.AdActivity" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
      android:theme="@android:style/Theme.Translucent" /> 

在XML活动的布局我用:

<com.google.android.gms.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/id"> 
    </com.google.android.gms.ads.AdView> 

在主要活动我的Java代码:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mAdView = (AdView) findViewById(R.id.adView); 
     adRequest = new AdRequest.Builder().build(); 
     mAdView.loadAd(adRequest); 

可惜这并未没有工作,我收到此错误

error: No resource identifier found for attribute 'adSize' in package

回答

1

其他遇到此问题的人通过在自定义布局nampespace中将/res替换为/lib解决了问题。

xmlns:android="http://schemas.android.com/apk/res/android" will be 

xmlns:yourApp="http://schemas.android.com/apk/lib/com.yourApppackage.yourClass" 
相关问题