1.启动页延时跳转+沉浸状态栏+启动页图片全屏
public class SplashActivity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*沉浸状态栏,即使状态栏颜色透明*/
/* View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
getWindow().setStatusBarColor(Color.TRANSPARENT);*/
/**************************************/
//去除标题栏
// requestWindowFeature(Window.FEATURE_NO_TITLE);
//去掉Activity上面的状态栏
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
WindowManager.LayoutParams. FLAG_FULLSCREEN);
/**************************************/
setContentView(R.layout.activity_splash);
//延时2秒跳转MainActivity
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
}
}, 2000); //2秒
}
}
activity_splash.xml: (主要代码是android:scaleType="fitXY",x轴,y轴分别拉伸图片)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/splash_bg_img"
android:src="@mipmap/splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
/>
</RelativeLayout>
2.解决启动白屏问题:
再values/color中添加#90FFFFFF透明色
<color name="transparent">#90FFFFFF</color>
在style中添加主题
</style>
<style name="AppTransparentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
在Androidmainfest.xml设置:
<activity android:name=".SplashActivity" android:theme="@style/AppTransparentTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>