android app 启动会白屏的解决办法
16lz
2021-12-04
原因:由于Activity只能到onResume时,才能展示到前台,所以,如果为MAIN activity设置背景的话,无论onCreate-onResume速度多快,都会出现短暂的白屏。
解决办法:
1:只要在配置文件内activity属性配置内加上android:theme="@android:style/Theme.Translucent" 就好了。
这样就调用了android的透明样式!
2:通过style样式来解决问题,在解决透明问题并且设定了NoTitle
主题Theme就是用来设置界面UI风格,可以设置整个应用或者某个活动Activity的界面风格。在Android SDK中内置了下面的Theme,可以按标题栏Title Bar和状态栏Status Bar是否可见来分类:
[html] view plain copy print ?
- •android:theme="@android:style/Theme.Dialog" 将一个Activity显示为能话框模式
- •android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏
- •android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏
- •android:theme="Theme.Light" 背景为白色
- •android:theme="Theme.Light.NoTitleBar" 白色背景并无标题栏
- •android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏
- •android:theme="Theme.Black" 背景黑色
- •android:theme="Theme.Black.NoTitleBar" 黑色背景并无标题栏
- •android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏
- •android:theme="Theme.Wallpaper" 用系统桌面为应用程序背景
- •android:theme="Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏
- •android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏
- •android:theme="Translucent" 半透明
- •android:theme="Theme.Translucent.NoTitleBar" 半透明、无标题栏
- •android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、无标题栏、全屏
- •android:theme="Theme.Panel"
- •android:theme="Theme.Light.Panel"
Drawable资源是对图像的一个抽象,你可以通过getDrawable(int)得到并绘制到屏幕上。这里有几种不同类型的Drawable:
Bitmap File
一个Bitmap图像文件(.png、.jpg或.gif)。BitmapDrawable。
Nine-Patch File
一个带有伸缩区域的PNG文件,可以基于content伸缩图片(.9.png)。NinePatchDrawable。
State List
一个XML文件,为不同的状态引用不同的Bitmap图像(例如,当按钮按下时使用不同的图片)。StateListDrawable。
Color
定义在XML中的资源,指定一个矩形(圆角可以有)的颜色。PaintDrawable。
Shape
一个XML文件,定义了一个几何形状,包括颜色和渐变。ShapeDrawable。
AnimationDrawable资源的说明在【Animation资源】文章中。
Bitmap File
基本的Bitmap图像。Android支持几种不同格式的Bitmap文件:.png(最佳)、.jpg(可接受)、.gif(不要)。
注意:Bitmap文件可能会被aapt工具进行无损图像压缩优化。例如,一个真彩色的PNG(不超过256色)可能会被转换成一个带有颜色板的8位PNG。这样做能保证图片质量一样,但减少内存占用。因此,需要了解的是放在这个文件夹下的二进制图像在编译时可能会发生变更。如果你打算以位流方式读取图像来转化成Bitmap的话,可以把它们放到res/raw文件中,在这里,它们不会被优化。
File Location:
res/drawable/filename.png (.png, .jpg, 或.gif)
文件名会被当作资源ID使用。
Complied Resource Datatype:
指向BitmapDrawable的资源指针。
Resource Reference:
R.drawable.filename(Java)
@[package:]drawable/filename(XML)
Example:
在res/drawable/myimage.png位置保存了一张图片,在Layout XML中可以应用这个图片到一个View上:
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/myimage" />
下面的代码可以以Drawable方式得到图片:
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.myimage);
Nine-Patch File
NinePatch是一种PNG图像,可以定义拉伸区域,当View的content超出图像边界的话,Android会拉伸它。典型用法是把这个图像设置为View的背景,而这个View至少有一个尺寸设置为“wrap_content”,当这个View变大来容纳content时,Nine-Patch图像也会拉伸来匹配View的大小。
File Location:
res/drawable/filename.9.png
文件名将被当作资源ID使用。
Complied Resource Datatype:
指向NinePatchDrawable的资源指针。
Resource Reference:
R.drawable.filename(Java)
@[package:]drawable/filename(XML)
Example:
在res/drawable/myninepatch.9.png位置保存了一张图片,在Layout XML中可以应用这个图片到一个View上: