我試圖在我的測試應用中包含廣告,當我在模擬器或設備上運行應用程序時,我得到一個橫幅添加Required XML attribute 「adSize」 was missing
。當我有xmlns時,缺少必需的XML屬性「adSize」:ads =「http://schemas.android.com/apk/lib/com.google.ads」set
我已經在com.google.android.gms.ads.AdView
標籤中設置了xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
。
不確定如何解決此問題。
更多細節:Android Studio AI-141.1989493
代碼片段:
AdView mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdUnitId("ca-app-pub-xxxxx/xxxxxx");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("E58D5904AA50D88E2FD63A1D1EF97B34")
.build();
mAdView.loadAd(adRequest);
AndroidManifest.xml中
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
activity_main.xml中
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/LinearLayout01">
<TableRow android:id="@+id/LinearLayout0">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxxxx/xxxxxx"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, E58D5904AA50D88E2FD63A1D1EF97B34">
</com.google.android.gms.ads.AdView>
謝謝,它爲我工作。 –