【安卓学习之常见问题】 Android 屏幕适配3 -- 启动页/引导页适配(冷启动)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ljb568838953/article/details/80168724

█ 【安卓学习之常见问题】 Android 屏幕适配3 – 启动页/引导页适配(冷启动)

█ 相关文章:

 ● 【安卓学习之常见问题】 Android 屏幕适配
 ● 【安卓学习之常见问题】 Android 屏幕适配2 – 全面屏适配
 ● 【安卓学习之常见问题】 Android 屏幕适配3 – 启动页/引导页适配

█ 问题:

 ● app开机启动有短暂的黑屏/白屏,之后才进入app的启动页面
这里写图片描述
这里写图片描述
 ● 在全面屏的手机上,还有虚拟导航,且显示为白色,和开机图之间有黑色缝隙!
 ● 这个问题可以百度android的冷启动,了解相关知识!

█ 百度:

 ● 1.app启动后,先进入冷启动,之后在进入app的LAUNCHER界面。因此在未进入LAUNCHER界面时,会先有一个冷启动显示的界面。

    什么是Android的冷启动时间?

冷启动时间是指用户从手机桌面点击APP的那一刻起到启动页面的Activity调用onCreate()方法之间的这个时间段。

 ● 2.网上提供的解决方法是:修改启动页的主题

冷启动页设置背景图(效果看起来app启动的快,推荐)
< style name=”AppWelcome” parent=”AppTheme” >
< item name=”android:windowBackground”>@mipmap/bg_welcome_start< /item >
< /style>
冷启动页设置透明色(效果看起来app启动的慢)
< style name=”Appwelcome” parent=”android:Theme.Translucent.NoTitleBar.Fullscreen”/ >

█ 实验:

 ● 修改styles.xml

<!-- Application theme. -->
<style name="AppTheme" parent="android:Theme.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
 < style name="logo_theme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowBackground">@drawable/logo_bg</item>
</style>

 ● 修改AndroidManifest.xml

<application
    android:allowBackup="false"
    android:hardwareAccelerated="false"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="false"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.test.them.activity.LoginActivity"
        android:configChanges="orientation|screenSize|locale|locale"
        android:label="@string/app_name"
        android:theme="@style/logo_theme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    < /application>

 ● 编译运行:开机logo图,有导航栏,黑底白图标,不是全屏模式
这里写图片描述

█ 总结:

 ● 这种方法,修改的代码比较少,但是开机logo图,有导航栏,黑底白图标,不是全屏模式
 ● 如果想要进一步处理的话,以及所有可以修改导航栏颜色的话,(猜测)可能需要类继承android.support.v7.app.AppCompatActivity,主题继承Theme.AppCompat.Light.DarkActionBar、Theme.AppCompat.Light.NoActionBar、Theme.AppCompat.NoActionBar
 

█ 20180519补充:

 ● PS:以下是打包好的三个供eclipse版本使用的android-support-v7包,其中【android-support-v7-appcompat_00.0.0_20150325.zip】 不知道是哪个版本的,【android-support-v7-appcompat_23.1.1_20151124.rar】是23.1.1版android6.0,【android-support-v7-appcompat_26.1.0_20170913.zip】是26.1.0版android8.0
这里写图片描述

下载地址:android-support-v7-appcompat(含23和26)_20180518.zip-CSDN下载(注意修改编译条件) 

 ● 修改状态栏的颜色:android.view.Window.setStatusBarColor(int arg0)有效的条件:
   1. 要引入android-support-v7-appcompat_23.1.1库,才有效(\project.properties)

android.library.reference.1=../../../../android-support-v7-appcompat_23.1.1_20151124/appcompat

   2. 修改Activity的主题:(\res\values\styles.xml)

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here.标题栏、状态栏、 CheckBox的颜色 -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

   3. 修改编译环境,API 23 即Android 6.0(\project.properties)

target=android-23

 ● 修改导航栏的颜色: android.view.Window.setNavigationBarColor(int arg0)有效的条件:
   1. 要引入android-support-v7-appcompat_26.1.0库,才有效(\project.properties)

android.library.reference.1=../../../../android-support-v7-appcompat_26.0.1_20170913/android-support-v7-appcompat26

   2. 修改Activity的主题:(\res\values\styles.xml)

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here.标题栏、状态栏、 CheckBox的颜色 -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

   3. 修改编译环境,API 26 即Android 8.0.0 (\project.properties)

target=android-26

█ 相关资料:

 ● 1.2014-11-07 Materi
 al Designer的低版本兼容实现(二)—— Theme - developer_Kale - 博客园

 ● 2.2016-08-28 Android冷启动实现APP秒开 - 李晨玮 - 简书
 ● 3.2017-07-12 Android APP 启动优化(冷启动) - code_dream_wq的博客 - CSDN博客
 ● 4.2017-11-29 手淘启动页全面屏和虚拟键适配 - 陆云帆 - CSDN博客
 ● 5.2017-06-01 搜图神器源码(3.4.0旧版本,新版本的没开源) - GitHub - wenhuaijun/SearchPictureTool - CSDN博客
 ● 6.2017-12-21 吴小龙同學 - GitHub - WuXiaolong/AndroidSamples: 整理我开发中遇到的问题及我的一些总结。

转载请注明出处:
http://blog.csdn.net/ljb568838953/article/details/80168724

猜你喜欢

转载自blog.csdn.net/ljb568838953/article/details/80168724