在接入第三方平台时,经常需要加上第三方的Logo启动页,不是每个平台都自己做好的,自己的平台已经有了,再加一个如何好呢?下面介绍一个方便快捷的方法,仅供参考,如有其它高见欢迎大家留言
第一步添加代码
package cn.mygame;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
public class StartView extends Activity {
private static Activity mContext = null;
int iDelayTime = 1000;//延时
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
Resources resources = mContext.getResources();
//获取layout文件夹底下的startview.xml文件的id号
int indentify = resources.getIdentifier(mContext.getPackageName()+":layout/"+"startview", null, null);
setContentView(indentify);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
handler.sendEmptyMessage(1); // 给UI主线程发送消息
}
}, iDelayTime); // 启动等待时间
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
switch (msg.what) {
case 1:
// 切换到主页面
Intent mainIntent = new Intent();
mainIntent.setClass(mContext,MyGame.class);
mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mContext.startActivity(mainIntent);
mContext.finish();//关闭当前的页面,一定要用finish
overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out); //添加了一个切换淡入淡出的效果
break;
}
}
};
}
第二步:在layout文件下建立你用到的startview.xml
给大家看一下内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="@drawable/startview" >
</ImageView>
</LinearLayout>
第三步:在drawable-hdpi,drawable-ldpi,drawable-mdpi,drawable-xhdpi分别放入图片资源,文件名一定要和你好xml中用到的一样,这里是startview
第四步:在主manifest里添加activity:
<activity
android:name="cn.mygame.StartView"
android:configChanges="keyboardHidden|orientation"
android:launchMode="standard" //注意模式
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
大概内容都已经贴上来了,大家相互研究一下吧