失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Cocos2dx---------------------添加Admob广告

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

时间:2021-12-24 07:40:34

相关推荐

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

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

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

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="/apk/res/android"xmlns:ads="/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.Cocos2dxGLSurfaceViewandroid:id="@+id/game_gl_surfaceview"android:layout_width="fill_parent"android:layout_height="fill_parent" /><RelativeLayoutandroid:id="@+id/ADLayout"android:layout_width="wrap_content"android:layout_height="wrap_content" ><com.google.ads.AdViewandroid: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>

即可

如果觉得《Cocos2dx---------------------添加Admob广告》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。