【问题标题】:Error adding AdMob with Xamarin Visual Studio使用 Xamarin Visual Studio 添加 AdMob 时出错
【发布时间】:2018-08-07 19:13:02
【问题描述】:

我对 Xamarin Visual Studio 有疑问,尤其是 AdMob 横幅。如何正确添加 AdMob 横幅?

我已成功下载组件(Google Play 服务 - 广告)。

这是我的代码:

MainActivity.cs

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
//using Android.Support.V7.App;
using Android.Gms.Ads;
using Android;

namespace App7
{
    [Activity(Label = "App7", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        AdView mAdView;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            ShowAdsBanner();
        }

        void ShowAdsBanner()
        {
            mAdView = FindViewById<AdView>(Resource.Id.adViewResult);
            var adRequest = new AdRequest.Builder().Build();
            // Start loading the ad.
            mAdView.LoadAd(adRequest);

        }
    }


}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="App7.App7" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="16" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:label="App7">
    <activity android:name="com.google.android.gms.ads.AdActivity" 
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
              android:theme="@android:style/Theme.Translucent" />
  </application>
</manifest>

Main.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/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/MyButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Hello" />
    <com.google.android.gms.ads.AdView
        android:id="@+id/adViewResult"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="my id here " />
</LinearLayout>

main.xml 中有错误

错误截图

【问题讨论】:

    标签: java android


    【解决方案1】:

    我建议确保更新所有组件,特别是 v7.appcompat 组件,因为它似乎与属性冲突。

    如果这不起作用,请尝试删除软件包并重新下载。

    我有一个项目当前设置了这两个组件,并且这两个属性在我构建时不会引发错误。祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多