1、产生原因

其实显示黑屏或者白屏实属正常,这是因为还没加载到布局文件,就已经显示了window窗口背景,黑屏白屏就是window窗口背景。

示例:

Android x86进入安装黑屏 android x86 黑屏_Android x86进入安装黑屏

2、解决办法

通过设置设置Style

(1)设置背景图Theme

通过设置一张背景图。 当程序启动时,首先显示这张背景图,避免出现黑屏

portrait
>@mipmap/splash
true
true

(2)设置透明Theme

通过把样式设置为透明,程序启动后不会黑屏而是整个透明了,等到界面初始化完才一次性显示出来

true
@android:color/transparent
true
portrait

两者对比:

Theme1 程序启动快,界面先显示背景图,然后再刷新其他界面控件。给人刷新不同步感觉。

Theme2 给人程序启动慢感觉,界面一次性刷出来,刷新同步。

(3)修改AndroidManifest.xml

android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true">
android:theme="@style/AppTheme">
//......

解决后示例:

Android x86进入安装黑屏 android x86 黑屏_android 启动黑屏解决方法_02

3、常见的Theme主题

android:theme="@android:style/Theme.Dialog" //Activity显示为对话框模式