Forum Libraries, Components, and Plugins
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Adding ads to Android project

Hi, I'm following this guide by the one and only Mr. Montemagno and I'm having trouble with some parts of it.
I added permissions but when I try to integrate the AdView the guide says "Simply open the layout file where the ad will live". I only have Toolbar and Tabbar under Layouts and I'm not even using them, I set the 'layout' like this:

this.SetContentView(application.AndroidContentView);

What Layout does my program use? Do I need to create a layout and set it in SetContentView? All my game is working on Application.AndroidContentView so if I change it, it probably won't show it. (I know, too many questions, I'm kind of lost :D )

What I did was add the code in the guide to my Toolbar layout but the compiler says:

    ads:adSize="SMART_BANNER" // <- attribute not declared
    ads:adUnitId="@string/banner_ad_unit_id" /> // <- attribute not declared

Also on this line:
var adView = FindViewById<AdView>(Resource.Id.adView);
it says: 'Resource.Id' does not contain a definition of AdView even though it is set on the Toolbar layout like this:
android:id="@+id/adView"
Any ideas on what's going on?

Best Answer

  • MarkedOneMarkedOne ARMember ✭✭
    Accepted Answer

    I was able to make ads work on Android, check uploaded files:

    • Properties/AndroidManifest.xml
    • Resources/layout/Main.axml
    • MainActivity.cs

Answers

  • KarhuKotiKarhuKoti USMember ✭✭

    Having the same problem here. Seems to be quite a few articles on it on the internet, but can't quite get it correct here.
    Br, Karhu.

  • MarkedOneMarkedOne ARMember ✭✭

    @KarhuKoti said:
    Having the same problem here. Seems to be quite a few articles on it on the internet, but can't quite get it correct here.
    Br, Karhu.

    I returned to the project, were you able to solve it? I'm still trying to add ads to my Android project.

  • MarkedOneMarkedOne ARMember ✭✭
    Accepted Answer

    I was able to make ads work on Android, check uploaded files:

    • Properties/AndroidManifest.xml
    • Resources/layout/Main.axml
    • MainActivity.cs
Sign In or Register to comment.