Reputation: 16429
I want to place a google ad in my project. But for some reason, I don't want to use Java language for this purpose. I have already tried the ads:loadAdOnCreate="true"
attribute, but I think it is not working now. Is there any idea by which I can display ads by using XML only?
Upvotes: 4
Views: 768
Reputation: 523
You should use old library of google ads
, so that loadAdOnCreate
will be available.
Upvotes: 3
Reputation: 35589
loadAdOnCreate
is no longer available in new SDK, you need to write java code to display your ads.
For ads integration you can check Harshad's answer
From official Doc by Amy Quispe (AdMob SDK Team)
loadAdOnCreate was deprecated in the Google Play Services version, so you'll have to load the ad from the code.
Upvotes: 3
Reputation: 1344
Use below code in xml say xml name is adview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/adView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dip"/>
Now in your Activity load the ad.
AdView adView = new AdView(this,AdSize.BANNER,"yourid");
LinearLayout ll= (LinearLayout) findViewById(R.id.adView);
ll.addView(adView);
AdRequest ar = new AdRequest();
ar.setGender(AdRequest.FEMALE);
adView.loadAd(ar);
You can include this view(xml) in any of your activity from xml like this..
<include layout="@layout/adview" /> // your xml
more detail visit here. Admob integration with simple-xml in Android?
Upvotes: 2