当前位置: 移动技术网 > IT编程>移动开发>Android > Android app启动时黑屏或者白屏的原因及解决办法

Android app启动时黑屏或者白屏的原因及解决办法

2019年07月24日  | 移动技术网IT编程  | 我要评论

731军妓电影,提子的功效与作用,巨野论坛

1、产生原因

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

示例:

2、解决办法

通过设置设置style

(1)设置背景图theme

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

<style name="apptheme" parent="theme.appcompat.light.darkactionbar">
    <item name="android:screenorientation">portrait</item>
    <item name="android:windowbackground">>@mipmap/splash</item>
    <item name="android:windowistranslucent">true</item>
    <item name="android:windownotitle">true</item>
</style>
 

(2)设置透明theme

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

<style name="apptheme" parent="theme.appcompat.light.darkactionbar">
    <item name="android:windownotitle">true</item>
    <item name="android:windowbackground">@android:color/transparent</item>
    <item name="android:windowistranslucent">true</item>
    <item name="android:screenorientation">portrait</item>
  </style>

两者对比:

theme1 程序启动快,界面先显示背景图,然后再刷新其他界面控件。给人刷新不同步感觉。
theme2 给人程序启动慢感觉,界面一次性刷出来,刷新同步。 

(3)修改androidmanifest.xml

<application
    android:name=".app"
    android:allowbackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsrtl="true">
    <activity android:name=".mainactivity"
     android:theme="@style/apptheme">
      <intent-filter>
        <action android:name="android.intent.action.main" />

        <category android:name="android.intent.category.launcher" />
      </intent-filter>
    </activity>

  //......

</application>

解决后示例:

3、常见的theme主题

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 app启动时黑屏或者白屏的原因及解决办法的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网