android开发 解决启动页空白或黑屏问题
遇到的情况:
app启动时进入启动页时出现白屏页,然后大概一秒之后就出现了背景图片。
原因:app启动时加载的是windows背景,之后再加载布局文件的,所以开始的黑屏/白屏就是windows的背景颜色,因此我们只要在启动页设置windows背景颜色就好了,那么在哪里设置呢? 就是theme里面。
解决办法:参考:【Android Drawable 那些不为人知的高效用法】
首先看之前的布局文件xml写法
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:background="@drawable/bg_app_welcome_1"/>
<LinearLayout
android:id="@+id/v_prepare_tips"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#007ed2"
android:text="首次安装正在准备数据"/>
<ProgressBar
android:layout_width="20dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"/>
</LinearLayout> </RelativeLayout>
=========================================================
优化之后的:
<!-- 只是将根元素的背景去掉了 -->
<?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" >
<LinearLayout
android:id="@+id/v_prepare_tips"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#007ed2"
android:text="首次安装正在准备数据"/>
<ProgressBar
android:layout_width="20dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</RelativeLayout>
设置style.xml
<style name="AppStartingBg" parent="@android:style/Theme.Holo.Light.NoActionBar" >
<item name="android:windowBackground">@drawable/bg_appstarting</item>
</style>
bg_appstarting.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<bitmap android:src="@drawable/bg_app_welcome_1" android:gravity="fill" />
</item>
</layer-list>
再在manifest.xml文件中添加该ancivity的theme
<activity
android:name="com.client.activity.AppStartingActivity"
android:icon="@drawable/ic_logo_2"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppStartingBg" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
大功告成!
android开发 解决启动页空白或黑屏问题的更多相关文章
- CentOS7安装vncserver(启动失败及连接黑屏解决办法)
CentOS7安装vncserver(启动失败及连接黑屏解决办法) 转载weixin_34167043 最后发布于2017-11-09 15:11:00 阅读数 42 收藏 展开 AutoSAR入门 ...
- Android实例-解决启动黑屏问题(XE8+小米2)
结果: 1.在启动时马上出现图片界面,但在出现程序界面前会有黑屏,大约有0.2秒左右. 实现: 1.建立2个文件:loading.png和styles.xml: ①其中loading.png是启动时替 ...
- Android APP应用启动页白屏(StartingWindow)优化
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 StartingWindow 的处理方式: 使用系统默认的 StartingWindow :用户点了应用图标启动应用,马上弹出系统默 ...
- Android Activity切换(跳转)时出现黑屏的解决方法
在两个Activity跳转时,由于第二个Activity在启动时加载了较多数据,就会在启动之前出现一个短暂的黑屏时间,解决这个问题比较简单的处理方法是将第二个Activity的主题设置成透明的,这样在 ...
- iOS开发 关于启动页和停留时间的设置
引言: 在开发一款商业App时,我们大都会为我们的App设置一个启动页. 苹果官方对于iOS启动页的设计说明: 为了增强应用程序启动时的用户体验,您应该提供一个启动图像.启动图像与应用程序的首屏幕看起 ...
- Android -- 使用主题配置文件,去掉程序启动界面的短暂黑屏
关于黑屏 默认的情况下,程序启动时,会有一个黑屏的时期,原因是,首个activity会加载一些数据,比如初始化列表数据等. 去除步骤 1./res/values/styles.xml 在 Theme ...
- egret 解决游戏loading前的黑屏
一.问题 egret游戏loading界面的制作可以参考这个,我就不多赘述啦,步骤也比较详细<Egret制作Loading页面及分步加载资源教程>. 后面我发现即便加上loading,在游 ...
- Android 解决启动页白屏或者黑屏的问题
欢迎页启动的线程由于请求和处理的数据量过大而,导致欢迎页在出现之前界面上会有一个短暂的白色闪屏停留,当然白色闪屏的停留是因为 application 的主题样式android:theme=@style ...
- android 启动时的短暂黑屏解决
http://blog.csdn.net/lonely_fireworks/article/details/22291835 http://www.cnblogs.com/henanjing/arch ...
随机推荐
- 对象之间的引用传递 之 .NET中的深拷贝和浅拷贝
1.场景 首先,场景是这样的. 有一个Person类,类中有一个类型是Car的属性.用于表述,人开的车. Car类中有一些描述诸如汽车拼盘之类的属性.基本场景就是这样. 2.浅拷贝 Person ...
- iPhone和iPad版本的分辨率a
- 遇到Wampserver遇到的问题
- 【Winform】DataTable绑定到ComboBox
我们从数据库中查询出来的数据存放在Datatable中 1.DataTable绑定到ComboBox上 cmbRole.DataSource = datatable; cmbRole.DisplayM ...
- C# Async与Await用法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- delphi 更改不了窗体的标题
delphi定义变量名千万要注意,不能和关键字同名,今天我无意间定义了一个caption的变量 导致我怎么都不能修改窗的标题.
- 淘宝:OceanBase分布式系统负载均衡案例分享
Heroku因"随机调度+Rails单线程处理导致延迟增加的负载均衡失败"的案例之后,我们在思考:在负载均衡测试时发现问题并妥善解决的成功经验有没有?于是,挖掘出"淘宝在 ...
- hdu 3530 Subsequence
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3530 Subsequence Description There is a sequence of i ...
- Android之Activity的四种启动模式
当应用运行起来后就会开启一条线程,线程中会运行一个任务栈,当Activity实例创建后就会放入任务栈中.Activity启动模式的设置在AndroidManifest.xml文件中,通过配置Activ ...
- 找到一个学习bootstrap的好网站
http://www.w3cschool.cc/bootstrap/bootstrap-css-overview.html