android App启动时的黑白屏问题解决

首先,在values/styles文件下加入下面代码

  <style name="AppTheme.StartingWindowTheme" >
          //这里设置的是启动图片
        <item name="android:windowBackground">@drawable/icon_start</item>
         <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>

然后,再去Androidmanifest里,在对应的Activity下添加主题样式

        android:theme="@style/AppTheme.StartingWindowTheme"

在这里,我附上案例,以便参考.

Androidmanifest.xml

  
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
   
     <application
        android:name=".data.others.App"
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

    <activity
            android:name=".ui.activity.StartActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="portrait"            //这一行是锁定屏幕代码,禁止横竖屏切换
            android:theme="@style/AppTheme.StartingWindowTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

values/styles.xml

     <resources>

           <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
              
                   <item name="android:windowBackground">@android:color/transparent</item>
            </style>
            
            <style name="AppTheme.StartingWindowTheme" parent="AppTheme">
                      //这里设置的是启动图片
                      <item name="android:windowBackground">@drawable/icon_start</item>
            </style>
    </resources>

在这里,有人会问了,你在values/styles.xml里写了两个样式是怎么回事,写成一个不行吗?
不行的,首先咱们先看第二个style (AppTheme.StartingWindowTheme) 这个是设置的启动页是的背景 ,所以只设置在启动页的Activty为样式.

启动页
启动页

在这里插入图片描述

大家经过图片的对比会发现,看似一样作用却是不一样的.
如果只设置一个启动页样式并也把他设置在application里,其他界面背景会变成启动页图片.
如还有疑问,欢迎留言.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值