美文网首页
Android开发中页面启动时黑屏或者白屏的原因及解决办法

Android开发中页面启动时黑屏或者白屏的原因及解决办法

作者: iflymoon | 来源:发表于2017-07-28 10:55 被阅读511次

产生原因

之所以会显示黑屏或者白屏是因为还没加载到布局文件,就已经显示了window窗口背景,黑屏白屏就是window窗口背景

解决办法

设置style,在主题中加入以下属性:
<item name="android:windowIsTranslucent">true</item>
如果是进入app的欢迎页出现这种情况还可以设置一个默认的背景图如下:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowBackground">@mipmap/splash</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowNoTitle">true</item>
</style>

之后只需要在AndroidManifest.xml中设置改主题就可以了

常见的主题

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="Theme.Translucent" //透明背景
android:theme="Theme.Translucent.NoTitleBar" //透明背景并无标题
android:theme="Theme.Translucent.NoTitleBar.Fullscreen" //透明背景并无标题,全屏
android:theme="Theme.Panel " //面板风格显示
android:theme="Theme.Light.Panel" //平板风格显示

相关文章

网友评论

      本文标题:Android开发中页面启动时黑屏或者白屏的原因及解决办法

      本文链接:https://www.haomeiwen.com/subject/wbexlxtx.html