写这篇文章,首先要感谢写此文章的人,其博客链接如下:
http://blog.csdn.net/zivensonice/article/details/51691136
其让我看到了事件发生的原委!
直接说解决方案:
方案一:
将加载页LoadingActivity.class(即初始化页面–判断是走引导页还是闪屏页的界面),此时的LoadingActivity.class中,没有添加setContentView(View view)去加载布局,而是直接判断跳转,
if(!aBoolean){// 不是第一次安装直接跳登录页面
startActivity(new Intent(LoadingActivity.this, SplashScreenActivity.class));
finish();
}else {
startActivity(new Intent(LoadingActivity.this,ActivityWelcome.class));
finish();
}
在AndroidMainFest.xml中配置添加自定义style/themeStyle
<activity
**android:theme="@style/themeStyle"**
android:name=".activity.LoadingActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
//是否要充满全屏此属性,看效果添加(有时候添加了后,会出现图片的动画效果)
<!-- <item name="android:windowFullscreen">true</item>-->
<style name="themeStyle" parent="Theme.AppCompat.Light.NoActionBar">
//此添加的图片和闪屏页的背景图片是一样的,其name为name = "android:background",而非 <item name="android:windowBackground">,此两种name目前还不知道区别,在项目中可以试下如何使用
<item name="android:background">@drawable/start</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
然后在闪屏页中也布局添加图片为:
<ImageView
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/start" />
即可解决问题
方案二:
直接在加载页LoadingActivity.class页面中添加setContentView(R.layout.activity_loading);
R.layout.activity_loading如下:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/bg_splash"/>
然后直接判断跳转:和第一种方法,跳转页面有所不同,即不是第一次登陆的时候,
if (isFirstInstall) {
// 第一次进入引导页
startActivity(new Intent(LoadingActivity.this, ActivityWelcome.class));
finish();
} else {
// 其他,进去登录页
startActivity(new Intent(LoadingActivity.this, LoginActivity.class));
finish();
}
第三种:
去掉启动白屏的现象:
1,设置系统主题样式,添加新的属性
<style name="AppTheme" parent="@android:style/Theme.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
2,设置主界面启动样式(背景图片等等)(1,可以单独使用,无需配合下面操作)
<style name="AppTheme.Launcher" parent="@android:style/Theme">
<item name="android:src">@drawable/background</item>
</style>
3,设置主界面的引用样式
设置主界面样式 android:theme="@style/AppTheme.Launcher"
并在主界面的onCreat调用时,设置样式为this.setTheme(@style/AppTheme);设置回到以前默认样式,并再super之前调用
以上,即可