开发者

Admob With Android Java Code

I want to use AdMob but I want to write it in purely Java using no XML. How can I display ads with the view class?

Here is where I want to present it. Because I am using framework code, here is where I draw my pixmaps. And this is where the AdMob will be presented:

   public void present(float deltaTim开发者_JS百科e) {
        Graphics g = game.getGraphics();
        g.drawPixmap(Assets.background, 0, 0);
        g.drawPixmap(Assets.logo, 35, 30);
        g.drawPixmap(Assets.play, 74, 220);
        // Create the adView


 AdView adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());

Taken from: http://code.google.com/mobile/ads/docs/android/fundamentals.html

You'll have to work with xml to add it to the Manifest and permissions though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜