要解决这个问题其实挺简单的只需要一个样式style即可
1、在style.xml中添加下面的style 设置启动图片
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- 欢迎页背景 -->
<item name="android:windowBackground">@mipmap/activity_welcom_bg_splash</item>
<item name="android:windowFullscreen">true</item>
</style>
2、在配置文件AndroidManifest.xml的启动activity中设置style
<activity
android:name=".login.Welcome"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
3、启动页activity
package com.first.mzystore.login;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import com.first.mzystore.R;
import com.first.mzystore.base.BaseActivity;
import com.first.mzystore.constant.SpKey;
import com.first.mzystore.home.HomeActivity;
import com.first.mzystore.utils.SpUtil;
import com.first.mzystore.utils.StatusBarUtil;
/**
* @Company
* @Created by wyx on 2016/1/21.
* @Description 欢迎页
* @version: v2.0
*/
public class Welcome extends Activity {
private AlphaAnimation mStart_anima;
View mView;
private ImageView mImgVHome;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//下面是一个线程 1秒后跳转到对应的页面
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
redirectTo();
}
}, 1000);
}
private void redirectTo() {
if (SpUtil.getInstance(this).getBoolean(SpKey.IS_FIRST_LOGIN, true)) {
startActivity(new Intent(this, com.first.mzystore.login.WelcomePagesActivity.class));
} else {
if(SpUtil.getInstance(this).getBoolean("isLogin", false)==false){
if(SpUtil.getInstance(this).getInt("USER_LOGIN_WAY",0)==1){
startActivity(new Intent(this, HomeActivity.class));
}else {
SpUtil.getInstance(this).put("loginType", 1);
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
}
}else {
startActivity(new Intent(this, HomeActivity.class));
}
}
finish();
}
}
4、这样就解决了启动页黑屏的问题,能够瞬间打开 。如果好用就给个赞吧****
网友评论