Cocos2dx---------------------添加Admob广告

1.先添加admob所需要的jar包

2.在所依赖的libcocos2dx工程里面添加main.xml

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

<!--     <EditText -->
<!--         android:id="@+id/textField" -->
<!--         android:layout_width="fill_parent" -->
<!--         android:layout_height="wrap_content" -->
<!--         android:background="@null" /> -->

    <org.cocos2dx.lib.Cocos2dxGLSurfaceView
        android:id="@+id/game_gl_surfaceview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <RelativeLayout
        android:id="@+id/ADLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            ads:adSize="BANNER"
            ads:adUnitId="a14eafbb0936d03"
            ads:loadAdOnCreate="true" />
    </RelativeLayout>

</FrameLayout>

3.修改Cocos2dxActivity.java

   将this.init()----->myInit();

	private void myInit()
	{
		setContentView(R.layout.main);
		
		mGLSurefaceView = (Cocos2dxGLSurfaceView) findViewById(R.id.game_gl_surfaceview);
		
		mGLSurefaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
		
	}

4. 清单文件里面

 <!-- *********   Admob   ********* -->
	    <activity android:name="com.google.ads.AdActivity"  
                    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>  
注意,使用的android sdk版本最好4.0及其以上

然后添加权限:

    <uses-permission android:name="android.permission.INTERNET" >
    </uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
    </uses-permission>

即可

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值