对于应用打开的第一个欢迎页面,一般我们会设置一个背景图片
比如:
<?xml version="1.0" encoding="utf-8"?>
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/iv_start"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
app:placeholderImage="@drawable/ic_splash"
app:actualImageScaleType="fitXY"
app:placeholderImageScaleType="fitXY"
style="@style/facebook_drawee_view_rect"
xmlns:app="http://schemas.android.com/apk/res-auto">
</com.facebook.drawee.view.SimpleDraweeView>
但是应用启动的时候,总会有几秒的白屏,给用户的体验不太好。
解决方案:
1. 定义自己的theme主题
<!-- theme 主题 -->
<style name="MyAppCompatTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@null</item>
<!--<item name="colorPrimary">@color/unsigned_color_black</item>-->
<item name="colorPrimaryDark">#999999</item>
<item name="colorAccent">#aaaaaa</item>
</style>
<style name="MyAppCompatTheme.NoActionBar.FullScreen" parent="MyAppCompatTheme.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@color/white</item>
</style>
<style name="MyAppCompatTheme.NoActionBar.FullScreen_Splash" parent="MyAppCompatTheme.NoActionBar.FullScreen">
<item name="android:windowBackground">@drawable/ic_splash</item>
</style>
2.给欢迎页设置theme
<!-- 欢迎界面 -->
<activity
android:name=".Activity.WelcomeActivity"
android:screenOrientation="portrait"
android:theme="@style/MyAppCompatTheme.NoActionBar.FullScreen_Splash"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
3.去掉我们在欢迎页xml中的背景图
<?xml version="1.0" encoding="utf-8"?>
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/iv_start"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
app:actualImageScaleType="fitXY"
app:placeholderImageScaleType="fitXY"
style="@style/facebook_drawee_view_rect"
xmlns:app="http://schemas.android.com/apk/res-auto">
</com.facebook.drawee.view.SimpleDraweeView>
4.这样就可以在应用启动的瞬间加载我们的背景图片,给用户的体验也会比较好。
此外,还可以在应用中设置背景色,来达到类似今日头条广告的效果
比如(判断是否有最新的图片,如果有就在应用启动后,加载背景,实现欢迎页背景切换的效果):
final SimpleDraweeView iv_start = (SimpleDraweeView) findViewById(R.id.iv_start);
String siFile = Local.getSifile();
if(!TextUtils.isEmpty(siFile)){
Log.i(TAG, "initViews: siFile:" + siFile);
File file = new File(siFile);
if(file.exists()) {
Uri uri = Uri.fromFile(file);
if(iv_start != null)
iv_start.setImageURI(uri);
}else{
Local.updateSiVersion(-1L);
}
}