首页 > 解决方案 > Android Studio Admob 错误属性未知

问题描述

我在放置广告横幅时遇到错误,如下面 的错误在这里

抱歉,它说您需要 10 或更多声望才能发布图片。

我的广告 XML 代码如下

<com.google.android.gms.ads.AdView
        android:id="@+id/adView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

据说我必须把代码: ads:adSize 放在那里,但每次我放ads:adSize它都会变成红色并变成错误:属性未知。

我错过了安装中的一些东西吗?

我该怎么做才能不会发生错误?

标签: androidandroid-studioads

解决方案


你需要一个属性ads:adSize="BANNER"

您可以使用以下代码添加代码:

final AdView adView = new AdView(getActivity());
adView.setAdUnitId("YourId");
adView.setAdSize(AdSize.BANNER);

推荐阅读