尝试实施广告时,缺少必需的xml属性“adSize”

时间:2017-12-26 22:15:10

标签: java android

我正在尝试在我的Android应用程序上获取广告,但横幅上写着“必需的xml属性”adsize“缺失。

以下是我广告的xml代码:

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.ckudesigns.hqtriviaguide.Main2Activity"
        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="ca-app-pub-3940256099942544/6300978111"/>

这是我的广告代码:

 import com.google.android.gms.ads.AdRequest;
 import com.google.android.gms.ads.AdView;
 import com.google.android.gms.ads.MobileAds;

 public class Main2Activity extends AppCompatActivity {
AdView mAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    MobileAds.initialize(this, "ca-app-pub-1802503500709247~1508244791");
    mAdView = (AdView)findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
    mAdView.loadAd(adRequest);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    addButtonClickListener();



    /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });*/
}



}

1 个答案:

答案 0 :(得分:0)

ads命名空间的名称空间声明不正确。你有这个:

xmlns:ads="http://schemas.android.com/apk/lib/com.ckudesigns.hqtriviaguide.Main2Activity"

相反,你应该这样:

xmlns:ads="http://schemas.android.com/apk/res-auto"