drawable中 splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@color/blue_user" />
<item
android:drawable="@drawable/logo"
android:gravity="center" />
</layer-list>
styles.xml中添加主题
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
SplashActivity
public class SplashActivity extends BaseActivity{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//判断用户是否是登录状态
SharedPreferences sharedPreferences = getSharedPreferences("user", Context.MODE_PRIVATE);
Integer isLogin=sharedPreferences.getInt("isLogin",0);
CookieMag cookieMag = new CookieMag("cookie");
//获取存储在本地的cookie
if(!cookieMag.get("Set-Cookie").equals("")&&isLogin==1){
//跳转到主页面
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}else{
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
}
finish();
}
}
AndroidManifest.xml
<activity android:name=".SplashActivity" android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>