缺少必需的XML属性“ adsize”(Google Play服务) [英] Required XML attribute 'adsize' was missing (google play service)

查看:193
本文介绍了缺少必需的XML属性“ adsize”(Google Play服务)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这样的问题,但不是重复的

There are so question like that but it's not duplicate

因为我已经使用过xmlns:ads = http://schemas.android.com/apk/ res-auto
,而我大部分都是在Java中完成代码

because i have already used xmlns:ads="http://schemas.android.com/apk/res-auto" and i have done code mostly in java

我想为广告使用Google Play服务

I want to use google play service for ads

我在Java代码下面使用了

I have used below java code

    com.google.android.gms.ads.AdView adView = (com.google.android.gms.ads.AdView) activity.findViewById(R.id.adview);
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId(activity.getString(R.string.admob_id));
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);

并遵循xml代码

 <com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
     />

但是我在横幅中遇到错误,就像

but i am getting error in banner is like

缺少XML的'adsize'属性

Requred XML attribute 'adsize' was missing

推荐答案

将命名空间更改为

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

Ad.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.google.android.gms.ads.AdView
        android:id="@+id/adview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER" />

</LinearLayout>

注意:

将此命名空间用于新的SDK

Use this Namespace for new SDK

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

这篇关于缺少必需的XML属性“ adsize”(Google Play服务)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆