zoukankan      html  css  js  c++  java
  • android开发 解决启动页空白或黑屏问题

    遇到的情况:

    app启动时进入启动页时出现白屏页,然后大概一秒之后就出现了背景图片。

    原因:app启动时加载的是windows背景,之后再加载布局文件的,所以开始的黑屏/白屏就是windows的背景颜色,因此我们只要在启动页设置windows背景颜色就好了,那么在哪里设置呢?  就是theme里面。

    解决办法:参考:【Android Drawable 那些不为人知的高效用法

    Android 启动APP时黑屏白屏的三个解决方案

    首先看之前的布局文件xml写法

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <ImageView 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:background="@drawable/bg_app_welcome_1"/>
        <LinearLayout 
            android:id="@+id/v_prepare_tips"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:orientation="horizontal"
            android:visibility="gone">
            <TextView 
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textColor="#007ed2"
                android:text="首次安装正在准备数据"/>
            <ProgressBar 
                android:layout_width="20dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"/>
        </LinearLayout>
        
    
    </RelativeLayout>

    =========================================================

    优化之后的:

    <!-- 只是将根元素的背景去掉了 -->
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <LinearLayout 
            android:id="@+id/v_prepare_tips"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:orientation="horizontal"
            android:visibility="gone">
            <TextView 
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textColor="#007ed2"
                android:text="首次安装正在准备数据"/>
            <ProgressBar 
                android:layout_width="20dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"/>
        </LinearLayout>
    </RelativeLayout>

    设置style.xml

        <style  name="AppStartingBg"  parent="@android:style/Theme.Holo.Light.NoActionBar" >  
            <item name="android:windowBackground">@drawable/bg_appstarting</item>  
        </style> 
    bg_appstarting.xml
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >   
          <item >  
             <bitmap android:src="@drawable/bg_app_welcome_1" android:gravity="fill" /> 
        </item>
    </layer-list>

    再在manifest.xml文件中添加该ancivity的theme

    <activity
                android:name="com.client.activity.AppStartingActivity"
                android:icon="@drawable/ic_logo_2"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@style/AppStartingBg" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

    大功告成!

  • 相关阅读:
    解决Docker时区与主机时区不一致的问题
    删除k8s中一直处于Terminating的资源
    多块盘制作成一个lvm
    Docker mysql启动自动按顺序导入sql
    linux中nfs启动报rpcbind.socket failed to listen on sockets: Address family not supported by protocol
    k8s容器挂载配置文件
    ssh到远程执行命令并返回
    安全组
    Python 字符串操作函数二
    Python 字符串操作函数一
  • 原文地址:https://www.cnblogs.com/feijian/p/4743154.html
Copyright © 2011-2022 走看看