android开发 解决启动页空白或黑屏问题
2015-08-19 19:16
471 查看
遇到的情况:
app启动时进入启动页时出现白屏页,然后大概一秒之后就出现了背景图片。
原因:app启动时加载的是windows背景,之后再加载布局文件的,所以开始的黑屏/白屏就是windows的背景颜色,因此我们只要在启动页设置windows背景颜色就好了,那么在哪里设置呢? 就是theme里面。
解决办法:参考:【Android Drawable 那些不为人知的高效用法】
【Android 启动APP时黑屏白屏的三个解决方案】
首先看之前的布局文件xml写法
=========================================================
优化之后的:
设置style.xml
再在manifest.xml文件中添加该ancivity的theme
大功告成!
app启动时进入启动页时出现白屏页,然后大概一秒之后就出现了背景图片。
原因:app启动时加载的是windows背景,之后再加载布局文件的,所以开始的黑屏/白屏就是windows的背景颜色,因此我们只要在启动页设置windows背景颜色就好了,那么在哪里设置呢? 就是theme里面。
解决办法:参考:【Android Drawable 那些不为人知的高效用法】
【Android 启动APP时黑屏白屏的三个解决方案】
首先看之前的布局文件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 BitmapUtil 工具类
- ListView 滑动时数据重复错位解决
- Android播放gif动画,增加屏幕掉金币效果
- Android播放gif动画,增加屏幕掉金币效果
- Android中级开发之Material Design-CardView初探
- Bitmap基本概念及在Android4.4系统上使用BitmapFactory的注意事项
- Android笔记(三)为按钮添加事件
- Android开发环境搭建,Activity生命周期,五大布局
- Android之如何实现自动拨号,打开网页的功能【超链接】
- Android之如何更改获取焦点的先后顺序
- Android之如何用TextView实现滚动字幕的效果【跑马灯】
- Android开发遇到问题汇总
- Android学习笔记之SoftReference软引用...
- Java,Android内存泄漏代码片段
- Android之Bitmap图片的截屏、模糊处理、传递、使用
- Android中的onActivityResult和setResult方法的使用
- Android studio 优化
- android 点滴——AsyncTask 和 Handler 比较
- Android 点滴——Handler用法总结
- Android重力感应飘树叶,晃动掉元宝